Skip to content

Commit 8f5beb8

Browse files
authored
[release/9.0] Fixes window backdrop and background in Windows 10 and window theme interactions with system changes (#10136)
* Fixes window theme reacting to system theme changes when application theme is not set to system * Fixes backdrop and window background in Windows 10
1 parent 3583df6 commit 8f5beb8

File tree

6 files changed

+105
-13
lines changed

6 files changed

+105
-13
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ internal static void OnSystemThemeChanged()
2828

2929
FluentThemeState newFluentThemeState = new FluentThemeState(Application.Current.ThemeMode.Value, useLightColors);
3030

31-
if (s_currentFluentThemeState == newFluentThemeState)
31+
if (s_currentFluentThemeState != newFluentThemeState)
3232
{
33-
return;
33+
AddOrUpdateThemeResources(Application.Current.Resources, GetThemeDictionary(Application.Current.ThemeMode));
3434
}
3535

36-
AddOrUpdateThemeResources(Application.Current.Resources, GetThemeDictionary(Application.Current.ThemeMode));
37-
3836
foreach (Window window in Application.Current.Windows)
3937
{
4038
if (window.ThemeMode == ThemeMode.None)

src/Microsoft.DotNet.Wpf/src/Themes/Generator/ThemeGenerator.Fluent.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ foreach($themeColor in $themeColors)
2020
xmlns:system="clr-namespace:System;assembly=System.Runtime"
2121
xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI"
2222
xmlns:theme="clr-namespace:Microsoft.Windows.Themes"
23-
xmlns:framework="clr-namespace:MS.Internal;assembly=PresentationFramework"
23+
xmlns:ms="clr-namespace:MS.Internal;assembly=PresentationFramework"
24+
xmlns:standard="clr-namespace:Standard;assembly=PresentationFramework"
2425
xmlns:base="clr-namespace:System.Windows;assembly=WindowsBase">
2526
</ResourceDictionary>'
2627

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/Window.xaml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<ResourceDictionary
99
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1010
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
11-
xmlns:framework="clr-namespace:MS.Internal;assembly=PresentationFramework"
11+
xmlns:ms="clr-namespace:MS.Internal;assembly=PresentationFramework"
12+
xmlns:standard="clr-namespace:Standard;assembly=PresentationFramework"
1213
xmlns:controls="clr-namespace:Fluent.Controls">
1314

1415
<ControlTemplate x:Key="WindowTemplateKey"
@@ -46,6 +47,15 @@
4647
Property="Visibility"
4748
Value="Visible"/>
4849
</MultiTrigger>
50+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
51+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
52+
</DataTrigger>
53+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
54+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
55+
</DataTrigger>
56+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
57+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
58+
</DataTrigger>
4959
</ControlTemplate.Triggers>
5060
</ControlTemplate>
5161

@@ -63,6 +73,17 @@
6373
<ContentPresenter x:Name="ContentPresenter" />
6474
</AdornerDecorator>
6575
</Border>
76+
<ControlTemplate.Triggers>
77+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
78+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
79+
</DataTrigger>
80+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
81+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
82+
</DataTrigger>
83+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
84+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
85+
</DataTrigger>
86+
</ControlTemplate.Triggers>
6687
</ControlTemplate>
6788
</Setter.Value>
6889
</Setter>
@@ -75,9 +96,12 @@
7596
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
7697
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
7798
</DataTrigger>
78-
<DataTrigger Binding="{Binding Path=(framework:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
99+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
79100
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
80101
</DataTrigger>
102+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
103+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
104+
</DataTrigger>
81105
</Style.Triggers>
82106
</Style>
83107

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.Dark.xaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:fluentcontrols="clr-namespace:Fluent.Controls" xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI" xmlns:theme="clr-namespace:Microsoft.Windows.Themes" xmlns:framework="clr-namespace:MS.Internal;assembly=PresentationFramework" xmlns:base="clr-namespace:System.Windows;assembly=WindowsBase">
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:fluentcontrols="clr-namespace:Fluent.Controls" xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI" xmlns:theme="clr-namespace:Microsoft.Windows.Themes" xmlns:ms="clr-namespace:MS.Internal;assembly=PresentationFramework" xmlns:standard="clr-namespace:Standard;assembly=PresentationFramework" xmlns:base="clr-namespace:System.Windows;assembly=WindowsBase">
22
<ContextMenu x:Key="DefaultControlContextMenu">
33
<MenuItem Command="ApplicationCommands.Copy" />
44
<MenuItem Command="ApplicationCommands.Cut" />
@@ -4800,6 +4800,15 @@
48004800
</MultiTrigger.Conditions>
48014801
<Setter TargetName="WindowResizeGrip" Property="Visibility" Value="Visible" />
48024802
</MultiTrigger>
4803+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
4804+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4805+
</DataTrigger>
4806+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4807+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4808+
</DataTrigger>
4809+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
4810+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4811+
</DataTrigger>
48034812
</ControlTemplate.Triggers>
48044813
</ControlTemplate>
48054814
<Style x:Key="DefaultWindowStyle" TargetType="{x:Type Window}">
@@ -4814,6 +4823,17 @@
48144823
<ContentPresenter x:Name="ContentPresenter" />
48154824
</AdornerDecorator>
48164825
</Border>
4826+
<ControlTemplate.Triggers>
4827+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
4828+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4829+
</DataTrigger>
4830+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4831+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4832+
</DataTrigger>
4833+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
4834+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4835+
</DataTrigger>
4836+
</ControlTemplate.Triggers>
48174837
</ControlTemplate>
48184838
</Setter.Value>
48194839
</Setter>
@@ -4824,7 +4844,10 @@
48244844
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
48254845
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
48264846
</DataTrigger>
4827-
<DataTrigger Binding="{Binding Path=(framework:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4847+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4848+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4849+
</DataTrigger>
4850+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
48284851
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
48294852
</DataTrigger>
48304853
</Style.Triggers>

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.HC.xaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:fluentcontrols="clr-namespace:Fluent.Controls" xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI" xmlns:theme="clr-namespace:Microsoft.Windows.Themes" xmlns:framework="clr-namespace:MS.Internal;assembly=PresentationFramework" xmlns:base="clr-namespace:System.Windows;assembly=WindowsBase">
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:fluentcontrols="clr-namespace:Fluent.Controls" xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI" xmlns:theme="clr-namespace:Microsoft.Windows.Themes" xmlns:ms="clr-namespace:MS.Internal;assembly=PresentationFramework" xmlns:standard="clr-namespace:Standard;assembly=PresentationFramework" xmlns:base="clr-namespace:System.Windows;assembly=WindowsBase">
22
<ContextMenu x:Key="DefaultControlContextMenu">
33
<MenuItem Command="ApplicationCommands.Copy" />
44
<MenuItem Command="ApplicationCommands.Cut" />
@@ -4781,6 +4781,15 @@
47814781
</MultiTrigger.Conditions>
47824782
<Setter TargetName="WindowResizeGrip" Property="Visibility" Value="Visible" />
47834783
</MultiTrigger>
4784+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
4785+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4786+
</DataTrigger>
4787+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4788+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4789+
</DataTrigger>
4790+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
4791+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4792+
</DataTrigger>
47844793
</ControlTemplate.Triggers>
47854794
</ControlTemplate>
47864795
<Style x:Key="DefaultWindowStyle" TargetType="{x:Type Window}">
@@ -4795,6 +4804,17 @@
47954804
<ContentPresenter x:Name="ContentPresenter" />
47964805
</AdornerDecorator>
47974806
</Border>
4807+
<ControlTemplate.Triggers>
4808+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
4809+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4810+
</DataTrigger>
4811+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4812+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4813+
</DataTrigger>
4814+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
4815+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4816+
</DataTrigger>
4817+
</ControlTemplate.Triggers>
47984818
</ControlTemplate>
47994819
</Setter.Value>
48004820
</Setter>
@@ -4805,7 +4825,10 @@
48054825
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
48064826
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
48074827
</DataTrigger>
4808-
<DataTrigger Binding="{Binding Path=(framework:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4828+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4829+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4830+
</DataTrigger>
4831+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
48094832
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
48104833
</DataTrigger>
48114834
</Style.Triggers>

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.Light.xaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:fluentcontrols="clr-namespace:Fluent.Controls" xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI" xmlns:theme="clr-namespace:Microsoft.Windows.Themes" xmlns:framework="clr-namespace:MS.Internal;assembly=PresentationFramework" xmlns:base="clr-namespace:System.Windows;assembly=WindowsBase">
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:fluentcontrols="clr-namespace:Fluent.Controls" xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI" xmlns:theme="clr-namespace:Microsoft.Windows.Themes" xmlns:ms="clr-namespace:MS.Internal;assembly=PresentationFramework" xmlns:standard="clr-namespace:Standard;assembly=PresentationFramework" xmlns:base="clr-namespace:System.Windows;assembly=WindowsBase">
22
<ContextMenu x:Key="DefaultControlContextMenu">
33
<MenuItem Command="ApplicationCommands.Copy" />
44
<MenuItem Command="ApplicationCommands.Cut" />
@@ -4797,6 +4797,15 @@
47974797
</MultiTrigger.Conditions>
47984798
<Setter TargetName="WindowResizeGrip" Property="Visibility" Value="Visible" />
47994799
</MultiTrigger>
4800+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
4801+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4802+
</DataTrigger>
4803+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4804+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4805+
</DataTrigger>
4806+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
4807+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4808+
</DataTrigger>
48004809
</ControlTemplate.Triggers>
48014810
</ControlTemplate>
48024811
<Style x:Key="DefaultWindowStyle" TargetType="{x:Type Window}">
@@ -4811,6 +4820,17 @@
48114820
<ContentPresenter x:Name="ContentPresenter" />
48124821
</AdornerDecorator>
48134822
</Border>
4823+
<ControlTemplate.Triggers>
4824+
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
4825+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4826+
</DataTrigger>
4827+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4828+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4829+
</DataTrigger>
4830+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
4831+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4832+
</DataTrigger>
4833+
</ControlTemplate.Triggers>
48144834
</ControlTemplate>
48154835
</Setter.Value>
48164836
</Setter>
@@ -4821,7 +4841,10 @@
48214841
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
48224842
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
48234843
</DataTrigger>
4824-
<DataTrigger Binding="{Binding Path=(framework:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4844+
<DataTrigger Binding="{Binding Path=(ms:FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop)}" Value="True">
4845+
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
4846+
</DataTrigger>
4847+
<DataTrigger Binding="{Binding Path=(standard:Utility.IsOSWindows11OrNewer)}" Value="False">
48254848
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
48264849
</DataTrigger>
48274850
</Style.Triggers>

0 commit comments

Comments
 (0)