Skip to content

Commit 18609a8

Browse files
authored
Merge pull request #3231 from MahApps/feature/GH_3227_Add_dynamic_created_ResDict_to_ThemeManager
(GH-3227) Fix for ThemeManager: dynamic accents only work once
2 parents e583d3d + 86a5047 commit 18609a8

28 files changed

+474
-126
lines changed

src/Directory.build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<ItemGroup>
1717
<None Remove="**\*.png;**\*.jpg;**\*.ico"/>
1818
<Resource Include="**\*.png;**\*.jpg;**\*.ico"/>
19-
<Compile DependentUpon="%(Filename)" SubType="Code" Update="**\*.g$(_SdkLanguageExtension)"/>
2019
</ItemGroup>
2120
<!-- workaround for https://github.com/NuGet/Home/issues/5894 -->
2221
<Import Condition=" '$(MSBuildProjectExtension)' == '.tmp_proj'" Project="obj\*.targets"/>

src/MahApps.Metro.Samples/MahApps.Metro.Caliburn.Demo/MahApps.Metro.Caliburn.Demo.csproj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,27 @@
88
</PropertyGroup>
99
<PropertyGroup>
1010
<OutputType>WinExe</OutputType>
11-
<StartupObject/>
11+
<StartupObject />
1212
<NoWarn>SA1652</NoWarn>
1313
<ApplicationIcon>mahapps.metro.logo2.ico</ApplicationIcon>
1414
<ApplicationManifest>app.manifest</ApplicationManifest>
1515
</PropertyGroup>
1616
<ItemGroup>
17-
<ProjectReference Include="..\..\MahApps.Metro\MahApps.Metro.csproj"/>
17+
<ProjectReference Include="..\..\MahApps.Metro\MahApps.Metro.csproj" />
1818
</ItemGroup>
1919
<ItemGroup>
20-
<Reference Include="System.ComponentModel.Composition"/>
20+
<Reference Include="System.ComponentModel.Composition" />
2121
</ItemGroup>
2222
<ItemGroup>
23-
<None Include="app.manifest"/>
24-
<None Include="paket.references"/>
25-
<None Remove="App.config"/>
23+
<None Include="app.manifest" />
24+
<None Include="paket.references" />
25+
<None Remove="App.config" />
2626
<AppConfigWithTargetPath Include="App.$(TargetFramework).config">
2727
<TargetPath>$(AssemblyName).config</TargetPath>
2828
</AppConfigWithTargetPath>
2929
</ItemGroup>
30-
<Import Project="..\..\.paket\Paket.Restore.targets"/>
30+
<ItemGroup>
31+
<Compile DependentUpon="%(Filename)" SubType="Code" Update="$(MSBuildProjectDirectory)\obj\**\*.g$(_SdkLanguageExtension)" />
32+
</ItemGroup>
33+
<Import Project="..\..\.paket\Paket.Restore.targets" />
3134
</Project>

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.csproj

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,32 @@
99
</PropertyGroup>
1010
<PropertyGroup>
1111
<OutputType>WinExe</OutputType>
12-
<StartupObject/>
12+
<StartupObject />
1313
<NoWarn>SA1652</NoWarn>
1414
<ApplicationIcon>mahapps.metro.logo2.ico</ApplicationIcon>
1515
<ApplicationManifest>app.manifest</ApplicationManifest>
1616
</PropertyGroup>
1717
<ItemGroup>
18-
<ProjectReference Include="..\..\MahApps.Metro\MahApps.Metro.csproj"/>
18+
<ProjectReference Include="..\..\MahApps.Metro\MahApps.Metro.csproj" />
1919
</ItemGroup>
2020
<ItemGroup>
21-
<Reference Include="System.ComponentModel.DataAnnotations"/>
22-
<Reference Include="System.Configuration"/>
23-
<Reference Include="System.Data.DataSetExtensions"/>
24-
<Reference Include="System.Data"/>
25-
<Reference Include="System.Windows.Forms"/>
26-
<Reference Include="WindowsFormsIntegration"/>
21+
<Reference Include="System.ComponentModel.DataAnnotations" />
22+
<Reference Include="System.Configuration" />
23+
<Reference Include="System.Data.DataSetExtensions" />
24+
<Reference Include="System.Data" />
25+
<Reference Include="System.Windows.Forms" />
26+
<Reference Include="WindowsFormsIntegration" />
2727
</ItemGroup>
2828
<ItemGroup>
29-
<None Include="app.manifest"/>
30-
<None Include="paket.references"/>
31-
<None Remove="App.config"/>
29+
<None Include="app.manifest" />
30+
<None Include="paket.references" />
31+
<None Remove="App.config" />
3232
<AppConfigWithTargetPath Include="App.$(TargetFramework).config">
3333
<TargetPath>$(AssemblyName).config</TargetPath>
3434
</AppConfigWithTargetPath>
3535
</ItemGroup>
36-
<Import Project="..\..\.paket\Paket.Restore.targets"/>
36+
<ItemGroup>
37+
<Compile DependentUpon="%(Filename)" SubType="Code" Update="$(MSBuildProjectDirectory)\obj\**\*.g$(_SdkLanguageExtension)" />
38+
</ItemGroup>
39+
<Import Project="..\..\.paket\Paket.Restore.targets" />
3740
</Project>

src/MahApps.Metro.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MahApps.Metro.Caliburn.Demo
1616
EndProject
1717
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MahApps.Metro.Tests", "Mahapps.Metro.Tests\MahApps.Metro.Tests.csproj", "{40048BCF-D1C7-46CC-B781-05718BE25BFC}"
1818
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EC5373FC-2098-4D7B-8990-B15E9C631AE8}"
20+
ProjectSection(SolutionItems) = preProject
21+
Directory.build.props = Directory.build.props
22+
Directory.build.targets = Directory.build.targets
23+
EndProjectSection
24+
EndProject
1925
Global
2026
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2127
Debug|Any CPU = Debug|Any CPU

src/MahApps.Metro/MahApps.Metro.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
</PropertyGroup>
1010
<ItemGroup>
11-
<Reference Include="System.ComponentModel.DataAnnotations"/>
12-
<Reference Include="System.Configuration"/>
11+
<Reference Include="System.ComponentModel.DataAnnotations" />
12+
<Reference Include="System.Configuration" />
1313
</ItemGroup>
1414
<!-- Items include -->
1515
<ItemGroup>
16-
<None Include="paket.references"/>
16+
<None Include="paket.references" />
1717
</ItemGroup>
18-
<Import Project="..\.paket\Paket.Restore.targets"/>
18+
<ItemGroup>
19+
<Compile DependentUpon="%(Filename)" SubType="Code" Update="$(MSBuildProjectDirectory)\obj\**\*.g$(_SdkLanguageExtension)" />
20+
</ItemGroup>
21+
<Import Project="..\.paket\Paket.Restore.targets" />
1922
</Project>

src/MahApps.Metro/ThemeManager/Accent.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// ReSharper disable once CheckNamespace
2+
23
namespace MahApps.Metro
34
{
45
using System;
56
using System.Diagnostics;
67
using System.Windows;
8+
using JetBrains.Annotations;
79

810
/// <summary>
911
/// An object that represents the foreground color for a <see cref="AppTheme"/>.
@@ -25,20 +27,35 @@ public class Accent
2527
/// Initializes a new instance of the Accent class.
2628
/// </summary>
2729
public Accent()
28-
{ }
30+
{
31+
}
2932

3033
/// <summary>
3134
/// Initializes a new instance of the Accent class.
3235
/// </summary>
3336
/// <param name="name">The name of the new Accent.</param>
3437
/// <param name="resourceAddress">The URI of the accent ResourceDictionary.</param>
35-
public Accent(string name, Uri resourceAddress)
38+
public Accent([NotNull] string name, [NotNull] Uri resourceAddress)
3639
{
3740
if (name == null) throw new ArgumentNullException(nameof(name));
3841
if (resourceAddress == null) throw new ArgumentNullException(nameof(resourceAddress));
3942

4043
this.Name = name;
41-
this.Resources = new ResourceDictionary {Source = resourceAddress};
44+
this.Resources = new ResourceDictionary { Source = resourceAddress };
45+
}
46+
47+
/// <summary>
48+
/// Initializes a new instance of the Accent class.
49+
/// </summary>
50+
/// <param name="name">The name of the new Accent.</param>
51+
/// <param name="resourceDictionary">The ResourceDictionary of the accent.</param>
52+
public Accent([NotNull] string name, [NotNull] ResourceDictionary resourceDictionary)
53+
{
54+
if (name == null) throw new ArgumentNullException(nameof(name));
55+
if (resourceDictionary == null) throw new ArgumentNullException(nameof(resourceDictionary));
56+
57+
this.Name = name;
58+
this.Resources = resourceDictionary;
4259
}
4360
}
4461
}

src/MahApps.Metro/ThemeManager/AppTheme.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// ReSharper disable once CheckNamespace
2+
23
namespace MahApps.Metro
34
{
45
using System;
56
using System.Diagnostics;
67
using System.Windows;
8+
using JetBrains.Annotations;
79

810
internal class AppName
911
{
@@ -19,7 +21,7 @@ public class AppTheme
1921
/// <summary>
2022
/// The ResourceDictionary that represents this application theme.
2123
/// </summary>
22-
public ResourceDictionary Resources {get; }
24+
public ResourceDictionary Resources { get; }
2325

2426
/// <summary>
2527
/// Gets the name of the application theme.
@@ -30,14 +32,28 @@ public class AppTheme
3032
/// Initializes a new instance of the AppTheme class.
3133
/// </summary>
3234
/// <param name="name">The name of the new AppTheme.</param>
33-
/// <param name="resourceAddress">The URI of the accent ResourceDictionary.</param>
34-
public AppTheme(string name, Uri resourceAddress)
35+
/// <param name="resourceAddress">The URI of the AppTheme ResourceDictionary.</param>
36+
public AppTheme([NotNull] string name, [NotNull] Uri resourceAddress)
3537
{
3638
if (name == null) throw new ArgumentNullException(nameof(name));
3739
if (resourceAddress == null) throw new ArgumentNullException(nameof(resourceAddress));
3840

3941
this.Name = name;
40-
this.Resources = new ResourceDictionary {Source = resourceAddress};
42+
this.Resources = new ResourceDictionary { Source = resourceAddress };
43+
}
44+
45+
/// <summary>
46+
/// Initializes a new instance of the AppTheme class.
47+
/// </summary>
48+
/// <param name="name">The name of the new AppTheme.</param>
49+
/// <param name="resourceDictionary">The ResourceDictionary of the accent.</param>
50+
public AppTheme([NotNull] string name, [NotNull] ResourceDictionary resourceDictionary)
51+
{
52+
if (name == null) throw new ArgumentNullException(nameof(name));
53+
if (resourceDictionary == null) throw new ArgumentNullException(nameof(resourceDictionary));
54+
55+
this.Name = name;
56+
this.Resources = resourceDictionary;
4157
}
4258
}
4359
}

0 commit comments

Comments
 (0)