Skip to content

Commit 4f5d896

Browse files
committed
Code Suggestion for #3736
#3736 I added some suggestions as a cloud patch (let me know if you have any trouble viewing it). Some key changes here: 1. You can access the environment variables to get the versions. I left some code showing how to do this. 2. You can setup a string property in the view model and bind that in the XAML rather than the code behind. 3. There are several TODO items I left in the cloud patch, let me know if you have any questions on them. 4. If you want to see my review of this, I did it it live on twitch. It is at the beginning of this stream. https://www.twitch.tv/videos/2318667161
1 parent ee61694 commit 4f5d896

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/MainDemo.Wpf/Domain/MainWindowViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, string? s
7272
private DemoItem? _selectedItem;
7373
private int _selectedIndex;
7474
private string? _searchKeyword;
75+
private string? _nugetVersions;
7576
private bool _controlsEnabled = true;
7677

7778
public string? SearchKeyword
@@ -86,6 +87,13 @@ public string? SearchKeyword
8687
}
8788
}
8889

90+
//TODO Set this property with the string for the version
91+
public string NugetVersions
92+
{
93+
get => _nugetVersions;
94+
set => SetProperty(ref _nugetVersions, value);
95+
}
96+
8997
public ObservableCollection<DemoItem> DemoItems { get; }
9098

9199
public DemoItem? SelectedItem

src/MainDemo.Wpf/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189

190190
<Separator />
191191

192+
<!-- TODO: Bind the text of this TextBlock to the NugetVersions property of the MainWindowViewModel -->
192193
<TextBlock x:Name="VersionText" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10" />
193194

194195
</StackPanel>

src/MainDemo.Wpf/MainWindow.xaml.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics;
2+
using System.Reflection;
23
using System.Threading;
34
using System.Windows.Media;
45
using MaterialDesignDemo.Domain;
@@ -120,16 +121,17 @@ private void LoadVersion()
120121
{
121122
try
122123
{
123-
string versionFilePath = Path.Combine(Directory.GetCurrentDirectory(), "version.txt");
124-
if (File.Exists(versionFilePath))
125-
{
126-
string version = File.ReadAllText(versionFilePath).Trim();
127-
VersionText.Text = $"Version: {version}";
128-
}
129-
else
130-
{
131-
VersionText.Text = "Version file not found";
132-
}
124+
//TODO: This should occur in the MainWindowViewModel
125+
var attributes = Assembly.GetAssembly(typeof(Theme))!
126+
.GetCustomAttributes<AssemblyMetadataAttribute>()
127+
.ToList();
128+
129+
var mdixVersion = attributes
130+
.SingleOrDefault(x => x.Key == "MDIXVersion")?.Value;
131+
132+
var mdixColorsVersion = attributes
133+
.SingleOrDefault(x => x.Key == "MDIXColorsVersion")?.Value;
134+
133135
}
134136
catch (Exception ex)
135137
{

src/MainDemo.Wpf/MaterialDesignDemo.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@
4949
<PackageReference Include="ShowMeTheXAML.AvalonEdit" />
5050
<PackageReference Include="ShowMeTheXAML.MSBuild" />
5151
</ItemGroup>
52+
53+
<!-- This passes the environment variable values into assembly attributes that can be read in code -->
54+
<ItemGroup>
55+
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
56+
<_Parameter1>MDIXVersion</_Parameter1>
57+
<_Parameter2>$(MDIXVersion)</_Parameter2>
58+
</AssemblyAttribute>
59+
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
60+
<_Parameter1>MDIXColorsVersion</_Parameter1>
61+
<_Parameter2>$(MDIXColorsVersion)</_Parameter2>
62+
</AssemblyAttribute>
63+
</ItemGroup>
5264
</Project>

0 commit comments

Comments
 (0)