Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,6 @@
<Compile Include="System\Windows\Documents\XPSS0ValidatingLoader.cs" />
<Compile Include="System\Windows\Documents\ZoomPercentageConverter.cs" />
<Compile Include="System\Windows\AccentColorHelper.cs" />
<Compile Include="System\Windows\DwmColorization.cs" />
<Compile Include="System\Windows\DynamicResourceExtension.cs" />
<Compile Include="System\Windows\DynamicResourceExtensionConverter.cs" />
<Compile Include="System\Windows\EventSetter.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ internal static void InitializeFluentTheme()
var themeColorResourceUri = GetFluentWindowThemeColorResourceUri(_currentApplicationTheme, _currentUseLightMode);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = themeColorResourceUri });

DwmColorization.UpdateAccentColors();
_isFluentThemeInitialized = true;
}
}
Expand Down Expand Up @@ -78,7 +77,7 @@ internal static void ApplySystemTheme(IEnumerable windows = null, bool forceUpda

string systemTheme = GetSystemTheme();
bool useLightMode = IsSystemThemeLight();
Color systemAccentColor = DwmColorization.GetSystemAccentColor();
Color systemAccentColor = AccentColorHelper.SystemAccentColor;
ApplyTheme(windows , systemTheme, useLightMode, systemAccentColor, forceUpdate);
}

Expand All @@ -101,9 +100,8 @@ private static void ApplyTheme(
if(forceUpdate ||
requestedTheme != _currentApplicationTheme ||
requestedUseLightMode != _currentUseLightMode ||
DwmColorization.GetSystemAccentColor() != DwmColorization.CurrentApplicationAccentColor)
requestedAccentColor != _currentSystemAccentColor)
{
DwmColorization.UpdateAccentColors();

Uri dictionaryUri = GetFluentWindowThemeColorResourceUri(requestedTheme, requestedUseLightMode);
AddOrUpdateThemeResources(dictionaryUri);
Expand All @@ -121,6 +119,7 @@ private static void ApplyTheme(

_currentApplicationTheme = requestedTheme;
_currentUseLightMode = requestedUseLightMode;
_currentSystemAccentColor = requestedAccentColor;
}
}

Expand Down Expand Up @@ -192,18 +191,14 @@ private static void AddOrUpdateThemeResources(Uri dictionaryUri)

var newDictionary = new ResourceDictionary() { Source = dictionaryUri };

ResourceDictionary currentDictionary = Application.Current?.Resources;
foreach (var key in newDictionary.Keys)
FindFluentThemeAndColorDictionary(out ResourceDictionary fluentDictionary, out ResourceDictionary colorDictionary);

if (colorDictionary != null)
{
if (currentDictionary.Contains(key))
{
currentDictionary[key] = newDictionary[key];
}
else
{
currentDictionary.Add(key, newDictionary[key]);
}
Application.Current.Resources.MergedDictionaries.Remove(colorDictionary);
}

Application.Current.Resources.MergedDictionaries.Add(newDictionary);
}

#endregion
Expand Down Expand Up @@ -232,6 +227,31 @@ private static Uri GetFluentWindowThemeColorResourceUri(string systemTheme, bool
return new Uri("pack://application:,,,/PresentationFramework.Fluent;component/Resources/Theme/" + themeColorFileName, UriKind.Absolute);
}

private static void FindFluentThemeAndColorDictionary(out ResourceDictionary fluentThemeDictionary, out ResourceDictionary fluentColorDictionary)
{
fluentThemeDictionary = null;
fluentColorDictionary = null;

if (Application.Current == null) return;

foreach (ResourceDictionary mergedDictionary in Application.Current.Resources.MergedDictionaries)
{
if (mergedDictionary.Source != null)
{
if (mergedDictionary.Source.ToString() == fluentResourceDictionaryUri)
{
fluentThemeDictionary = mergedDictionary;
}
else if (mergedDictionary.Source.ToString().StartsWith(fluentColorResourceUriPart))
{
fluentColorDictionary = mergedDictionary;
}
}
}
}



#endregion

#region Private Members
Expand All @@ -240,6 +260,9 @@ private static Uri GetFluentWindowThemeColorResourceUri(string systemTheme, bool

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 string _currentApplicationTheme;

private static bool _currentUseLightMode = true;
Expand All @@ -248,5 +271,7 @@ private static Uri GetFluentWindowThemeColorResourceUri(string systemTheme, bool

private static bool _isFluentThemeInitialized = false;

private static Color _currentSystemAccentColor = AccentColorHelper.SystemAccentColor;

#endregion
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Resources/Accent.xaml" />
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Resources/DefaultContextMenu.xaml" />
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Resources/DefaultFocusVisualStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Resources/Fonts.xaml" />
Expand Down
Loading