diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs index 82cb6873eeb..2e09516544f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs @@ -18,10 +18,18 @@ static ThemeManager() // TODO : Temprorary way of checking if setting Fluent theme enabled flag. Provide a property for theme switch. if (Application.Current != null) { + string dictionarySource; foreach (ResourceDictionary mergedDictionary in Application.Current.Resources.MergedDictionaries) { - if (mergedDictionary.Source != null && mergedDictionary.Source.ToString().EndsWith("Fluent.xaml")) + if (mergedDictionary.Source != null) { + dictionarySource = mergedDictionary.Source.ToString(); + + if (dictionarySource.EndsWith("Fluent.Light.xaml", StringComparison.OrdinalIgnoreCase) + || dictionarySource.EndsWith("Fluent.Dark.xaml", StringComparison.OrdinalIgnoreCase) + || dictionarySource.EndsWith("Fluent.HC.xaml", StringComparison.OrdinalIgnoreCase) + || dictionarySource.EndsWith("Fluent.xaml", StringComparison.OrdinalIgnoreCase)) + _isFluentThemeEnabled = true; break; } @@ -40,8 +48,8 @@ internal static void InitializeFluentTheme() _currentApplicationTheme = GetSystemTheme(); _currentUseLightMode = IsSystemThemeLight(); - var themeColorResourceUri = GetFluentWindowThemeColorResourceUri(_currentApplicationTheme, _currentUseLightMode); - Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = themeColorResourceUri }); + var themeColorResourceUri = GetFluentThemeResourceUri(_currentApplicationTheme, _currentUseLightMode); + AddOrUpdateThemeResources(themeColorResourceUri); _isFluentThemeInitialized = true; } @@ -103,7 +111,7 @@ private static void ApplyTheme( requestedAccentColor != _currentSystemAccentColor) { - Uri dictionaryUri = GetFluentWindowThemeColorResourceUri(requestedTheme, requestedUseLightMode); + Uri dictionaryUri = GetFluentThemeResourceUri(requestedTheme, requestedUseLightMode); AddOrUpdateThemeResources(dictionaryUri); foreach(Window window in windows) @@ -191,11 +199,11 @@ private static void AddOrUpdateThemeResources(Uri dictionaryUri) var newDictionary = new ResourceDictionary() { Source = dictionaryUri }; - FindFluentThemeAndColorDictionary(out ResourceDictionary fluentDictionary, out ResourceDictionary colorDictionary); + FindFluentThemeResourceDictionary(out ResourceDictionary fluentDictionary); - if (colorDictionary != null) + if (fluentDictionary != null) { - Application.Current.Resources.MergedDictionaries.Remove(colorDictionary); + Application.Current.Resources.MergedDictionaries.Remove(fluentDictionary); } Application.Current.Resources.MergedDictionaries.Add(newDictionary); @@ -215,22 +223,21 @@ private static void AddOrUpdateThemeResources(Uri dictionaryUri) #region Private Methods - private static Uri GetFluentWindowThemeColorResourceUri(string systemTheme, bool useLightMode) + private static Uri GetFluentThemeResourceUri(string systemTheme, bool useLightMode) { - string themeColorFileName = useLightMode ? "light.xaml" : "dark.xaml"; + string themeFileName = "Fluent." + (useLightMode ? "Light" : "Dark") + ".xaml"; if(SystemParameters.HighContrast) { - themeColorFileName = "hc.xaml"; + themeFileName = "Fluent.HC.xaml"; } - return new Uri("pack://application:,,,/PresentationFramework.Fluent;component/Resources/Theme/" + themeColorFileName, UriKind.Absolute); - } + return new Uri("pack://application:,,,/PresentationFramework.Fluent;component/Themes/" + themeFileName, UriKind.Absolute); + } - private static void FindFluentThemeAndColorDictionary(out ResourceDictionary fluentThemeDictionary, out ResourceDictionary fluentColorDictionary) + private static void FindFluentThemeResourceDictionary(out ResourceDictionary fluentDictionary) { - fluentThemeDictionary = null; - fluentColorDictionary = null; + fluentDictionary = null; if (Application.Current == null) return; @@ -238,20 +245,15 @@ private static void FindFluentThemeAndColorDictionary(out ResourceDictionary flu { if (mergedDictionary.Source != null) { - if (mergedDictionary.Source.ToString() == fluentResourceDictionaryUri) - { - fluentThemeDictionary = mergedDictionary; - } - else if (mergedDictionary.Source.ToString().StartsWith(fluentColorResourceUriPart)) + if (mergedDictionary.Source.ToString().Contains(fluentThemeResoruceDictionaryUri)) { - fluentColorDictionary = mergedDictionary; + fluentDictionary = mergedDictionary; + break; } } } } - - #endregion #region Private Members @@ -260,8 +262,7 @@ private static void FindFluentThemeAndColorDictionary(out ResourceDictionary flu private static readonly string _regPersonalizeKeyPath = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; - private static readonly string fluentResourceDictionaryUri = "pack://application:,,,/PresentationFramework.Fluent;component/Resources/Fluent.xaml"; - private static readonly string fluentColorResourceUriPart = "pack://application:,,,/PresentationFramework.Fluent;component/Resources/Theme/"; + private static readonly string fluentThemeResoruceDictionaryUri = "pack://application:,,,/PresentationFramework.Fluent;component/Themes/"; private static string _currentApplicationTheme; diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/Generator/ThemeGenerator.Fluent.ps1 b/src/Microsoft.DotNet.Wpf/src/Themes/Generator/ThemeGenerator.Fluent.ps1 new file mode 100644 index 00000000000..2dd67279fb5 --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/Themes/Generator/ThemeGenerator.Fluent.ps1 @@ -0,0 +1,45 @@ +[CmdletBinding(PositionalBinding=$false)] +Param( + [string][Alias('c')]$themeColor = "Light" +) + +$currentDir = Get-Location +$fluentThemeDir = Join-Path $currentDir "..\PresentationFramework.Fluent\" + +$outFilePath = Join-Path $fluentThemeDir "Themes\Fluent.$themeColor.xaml" + +$styleFilesDir = Join-Path $fluentThemeDir "Styles" +$resouceFilesDir = Join-Path $fluentThemeDir "Resources" +$themeColorFilePath = Join-Path $resouceFilesDir "Theme\$themeColor.xaml" + +[xml]$combinedXaml = ' + ' + +foreach ($file in Get-ChildItem $resouceFilesDir -Filter "*.xaml") { + if($file.BaseName -eq "Fluent") { + continue + } + [xml]$currentXaml = Get-Content $file + + $combinedXaml.ResourceDictionary.InnerXml += $currentXaml.ResourceDictionary.InnerXml +} + +[xml]$themeColorXaml = Get-Content $themeColorFilePath +$combinedXaml.ResourceDictionary.InnerXml += $themeColorXaml.ResourceDictionary.InnerXml + +foreach ($file in Get-ChildItem $styleFilesDir -Filter "*.xaml") { + [xml]$currentXaml = Get-Content $file + + $combinedXaml.ResourceDictionary.InnerXml += $currentXaml.ResourceDictionary.InnerXml +} + +([xml]$combinedXaml).Save($outFilePath) \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Resources/Variables.xaml b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Resources/Variables.xaml index ccff04a06d3..3e764fc25f9 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Resources/Variables.xaml +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Resources/Variables.xaml @@ -46,7 +46,7 @@ 10,0,30,0 24 - 12,1,0,3 + 32 diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/Calendar.xaml b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/Calendar.xaml index 897cf3e805a..1807342c2f2 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/Calendar.xaml +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/Calendar.xaml @@ -10,10 +10,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=System.Runtime"> - - - - - + - #FFFF0000 + - 11,5,11,6 - 1 - 8,0,0,0 - 14 - 22 - 22 + 11,5,11,6 + 1 + 8,0,0,0 + 14 + 22 + 22 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 11,5,11,6 + 1 + 8,0,0,0 + 14 + 22 + 22 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 12 + 20 + + 1 + 8,6,0,0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 12 + 14 + 20 + 28 + 40 + 68 + + + + + + + + 1,1,1,1 + 0,0,0,1 + 10,0,0,0 + 0,0,10,0 + 0,0,4,0 + 0,0,0,0 + 24 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 11,5,11,6 + 1 + 8,0,0,0 + 14 + 22 + 22 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 12 + 20 + + 1 + 8,6,0,0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 12 + 14 + 20 + 28 + 40 + 68 + + + + + + + + 1,1,1,1 + 0,0,0,1 + 10,0,0,0 + 0,0,10,0 + 0,0,4,0 + 0,0,0,0 + 24 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 11,5,11,6 + 1 + 8,0,0,0 + 14 + 22 + 22 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 12 + 20 + + 1 + 8,6,0,0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 12 + 14 + 20 + 28 + 40 + 68 + + + + + + + + 1,1,1,1 + 0,0,0,1 + 10,0,0,0 + 0,0,10,0 + 0,0,4,0 + 0,0,0,0 + 24 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +