Skip to content

Commit 0a13a85

Browse files
committed
Enabling Fluent as default style with opt-in switch
1 parent 8e815bb commit 0a13a85

File tree

10 files changed

+392
-19
lines changed

10 files changed

+392
-19
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Win32/UxThemeWrapper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ private static void GetThemeNameAndColor(out string themeName, out string themeC
297297
#endif
298298

299299
themeColor = themeColorSB.ToString();
300+
301+
if (FrameworkAppContextSwitches.EnableFluentTheme)
302+
{
303+
themeName = "Fluent";
304+
themeColor = ThemeManager.IsSystemThemeLight() ? "Light" : "Dark";
305+
}
300306
}
301307
else
302308
{

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Appearance/WindowBackdropManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ private static bool UpdateGlassFrame(IntPtr hwnd, WindowBackdropType backdropTyp
133133
#region Internal Properties
134134

135135
internal static bool IsBackdropEnabled => _isBackdropEnabled ??= Utility.IsWindows11_22H2OrNewer &&
136-
ThemeManager.IsFluentThemeEnabled &&
136+
(ThemeManager.IsFluentThemeEnabled ||
137+
FrameworkAppContextSwitches.EnableFluentTheme) &&
137138
!FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop;
138139

139140
private static bool? _isBackdropEnabled = null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public static double MessageFontSize
426426
get
427427
{
428428
// TODO : Find a better solution to this. Difference in default size of font in Fluent and other themes.
429-
if(ThemeManager.IsFluentThemeEnabled)
429+
if(ThemeManager.IsFluentThemeEnabled || FrameworkAppContextSwitches.EnableFluentTheme)
430430
{
431431
return ThemeManager.DefaultFluentThemeFontSize;
432432
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,16 @@ private static IntPtr SystemThemeFilterMessage(IntPtr hwnd, int msg, IntPtr wPar
14171417
{
14181418
ThemeManager.ApplySystemTheme();
14191419
}
1420+
1421+
if (FrameworkAppContextSwitches.EnableFluentTheme)
1422+
{
1423+
SystemColors.InvalidateCache();
1424+
SystemParameters.InvalidateCache();
1425+
SystemParameters.InvalidateDerivedThemeRelatedProperties();
1426+
ThemeManager.UpdateBackdropAndImmersiveMode();
1427+
OnThemeChanged();
1428+
InvalidateResources(false); // Only invalidate this thread's resources, other threads will get a chance
1429+
}
14201430
break;
14211431

14221432
case WindowMessage.WM_TABLET_ADDED:

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,31 @@ internal static void ApplySystemTheme(IEnumerable windows = null, bool forceUpda
8282
ApplyTheme(windows , systemTheme, useLightMode, systemAccentColor, forceUpdate);
8383
}
8484

85+
internal static void UpdateBackdropAndImmersiveMode(IEnumerable windows = null)
86+
{
87+
if (windows == null)
88+
{
89+
// If windows is not provided, apply the theme to all windows in the application.
90+
windows = Application.Current?.Windows;
91+
92+
if (windows == null)
93+
{
94+
return;
95+
}
96+
}
97+
98+
foreach (Window window in windows)
99+
{
100+
if (window == null)
101+
{
102+
continue;
103+
}
104+
105+
SetImmersiveDarkMode(window, !ThemeManager.IsSystemThemeLight());
106+
WindowBackdropManager.SetBackdrop(window, SystemParameters.HighContrast ? WindowBackdropType.None : WindowBackdropType.MainWindow);
107+
}
108+
}
109+
85110
/// <summary>
86111
/// Apply the requested theme and color mode to the windows.
87112
/// Checks if any update is needed before applying the changes.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,11 @@ internal void CreateSourceWindow(bool duringShow)
25212521
ThemeManager.ApplySystemTheme(this, true);
25222522
}
25232523

2524+
if (Standard.Utility.IsOSWindows11OrNewer && FrameworkAppContextSwitches.EnableFluentTheme)
2525+
{
2526+
ThemeManager.UpdateBackdropAndImmersiveMode();
2527+
}
2528+
25242529
// Sub classes can have different intialization. RBW does very minimalistic
25252530
// stuff in its override
25262531
SetupInitialState(requestedTop, requestedLeft, requestedWidth, requestedHeight);
@@ -3581,7 +3586,7 @@ private void Initialize()
35813586
}
35823587

35833588
// TODO : Remove when Fluent theme is enabled by default
3584-
if (ThemeManager.IsFluentThemeEnabled)
3589+
if (ThemeManager.IsFluentThemeEnabled || FrameworkAppContextSwitches.EnableFluentTheme)
35853590
{
35863591
if(WindowBackdropManager.IsBackdropEnabled)
35873592
{

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

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,159 @@
77

88
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
99

10-
<Style TargetType="{x:Type Frame}">
10+
<ControlTemplate x:Key="FrameNavChromeTemplateKey"
11+
TargetType="{x:Type Frame}">
12+
<Border Background="{TemplateBinding Background}"
13+
BorderBrush="{TemplateBinding BorderBrush}"
14+
BorderThickness="{TemplateBinding BorderThickness}"
15+
Padding="{TemplateBinding Padding}">
16+
<DockPanel>
17+
<Grid Background="{StaticResource NavigationWindowNavigationChromeBackground}"
18+
DockPanel.Dock="Top"
19+
Height="22">
20+
<Grid.ColumnDefinitions>
21+
<ColumnDefinition Width="Auto"/>
22+
<ColumnDefinition Width="Auto"/>
23+
<ColumnDefinition Width="16"/>
24+
<ColumnDefinition Width="*"/>
25+
</Grid.ColumnDefinitions>
26+
27+
<!-- Menu -->
28+
<Menu Name="NavMenu"
29+
Grid.ColumnSpan="3"
30+
Height="16"
31+
Margin="1,0,0,0"
32+
VerticalAlignment="Center"
33+
Style="{StaticResource NavigationWindowMenu}">
34+
35+
<MenuItem Padding="0,2,4,0"
36+
Style="{StaticResource NavigationWindowMenuItem}"
37+
ItemContainerStyle="{StaticResource NavigationWindowNavigationButtonJournalEntryStyle}"
38+
IsSubmenuOpen="{Binding Path=(MenuItem.IsSubmenuOpen),Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}">
39+
<MenuItem.ItemsSource>
40+
<MultiBinding Converter="{StaticResource JournalEntryUnifiedViewConverter}">
41+
<MultiBinding.Bindings>
42+
<Binding RelativeSource="{RelativeSource TemplatedParent}"
43+
Path="BackStack" />
44+
<Binding RelativeSource="{RelativeSource TemplatedParent}"
45+
Path="ForwardStack" />
46+
</MultiBinding.Bindings>
47+
</MultiBinding>
48+
</MenuItem.ItemsSource>
49+
</MenuItem>
50+
</Menu>
51+
52+
<Path Grid.Column="0"
53+
SnapsToDevicePixels="false"
54+
IsHitTestVisible="false"
55+
Margin="2,0,0,0"
56+
Grid.ColumnSpan="3"
57+
StrokeThickness="1"
58+
HorizontalAlignment="Left"
59+
VerticalAlignment="Center"
60+
Data="M22.5767,21.035 Q27,19.37 31.424,21.035 A12.5,12.5,0,0,0,53.5,13 A12.5,12.5,0,0,0,37.765,0.926 Q27,4.93 16.235,0.926 A12.5,12.5,0,0,0,0.5,13 A12.5,12.5,0,0,0,22.5767,21.035 z">
61+
<Path.Fill>
62+
<LinearGradientBrush StartPoint="0,0"
63+
EndPoint="0,1">
64+
<LinearGradientBrush.GradientStops>
65+
<GradientStopCollection>
66+
<GradientStop Color="#A0C2CCE7" Offset="0"/>
67+
<GradientStop Color="#60FFFFFF" Offset="1"/>
68+
</GradientStopCollection>
69+
</LinearGradientBrush.GradientStops>
70+
</LinearGradientBrush>
71+
</Path.Fill>
72+
73+
<Path.Stroke>
74+
<LinearGradientBrush StartPoint="0,0"
75+
EndPoint="0,1">
76+
<LinearGradientBrush.GradientStops>
77+
<GradientStopCollection>
78+
<GradientStop Color="#FFB7C2E3" Offset="0.2"/>
79+
<GradientStop Color="#A0FFFFFF" Offset="0.9"/>
80+
</GradientStopCollection>
81+
</LinearGradientBrush.GradientStops>
82+
</LinearGradientBrush>
83+
</Path.Stroke>
84+
<Path.LayoutTransform>
85+
<ScaleTransform ScaleX="0.667" ScaleY="0.667"/>
86+
</Path.LayoutTransform>
87+
</Path>
88+
89+
<Button Style="{StaticResource NavigationWindowBackButtonStyle}"
90+
Margin="3,0,1,0"
91+
Grid.Column="0">
92+
<Button.LayoutTransform>
93+
<ScaleTransform ScaleX="0.667" ScaleY="0.667"/>
94+
</Button.LayoutTransform>
95+
</Button>
96+
97+
98+
<Button Style="{StaticResource NavigationWindowForwardButtonStyle}"
99+
Margin="1,0,0,0"
100+
Grid.Column="1">
101+
<Button.LayoutTransform>
102+
<ScaleTransform ScaleX="0.667" ScaleY="0.667"/>
103+
</Button.LayoutTransform>
104+
</Button>
105+
</Grid>
106+
<ContentPresenter x:Name="PART_FrameCP"/>
107+
</DockPanel>
108+
</Border>
109+
<ControlTemplate.Triggers>
110+
<MultiTrigger>
111+
<MultiTrigger.Conditions>
112+
<Condition Property="CanGoForward"
113+
Value="false"/>
114+
<Condition Property="CanGoBack"
115+
Value="false"/>
116+
</MultiTrigger.Conditions>
117+
<Setter TargetName="NavMenu"
118+
Property="IsEnabled"
119+
Value="false"/>
120+
</MultiTrigger>
121+
</ControlTemplate.Triggers>
122+
</ControlTemplate>
123+
124+
125+
<Style x:Key="{x:Type Frame}"
126+
TargetType="{x:Type Frame}">
11127
<Setter Property="Background" Value="Transparent" />
12128
<Setter Property="NavigationUIVisibility" Value="Hidden" />
13129
<Setter Property="Padding" Value="0" />
14130
<Setter Property="Margin" Value="0" />
15131
<Setter Property="Focusable" Value="False" />
16132
<Setter Property="SnapsToDevicePixels" Value="True" />
133+
<Setter Property="Template">
134+
<Setter.Value>
135+
<ControlTemplate TargetType="{x:Type Frame}">
136+
<Border Background="{TemplateBinding Background}"
137+
BorderBrush="{TemplateBinding BorderBrush}"
138+
BorderThickness="{TemplateBinding BorderThickness}"
139+
Padding="{TemplateBinding Padding}">
140+
<ContentPresenter x:Name="PART_FrameCP"/>
141+
</Border>
142+
</ControlTemplate>
143+
</Setter.Value>
144+
</Setter>
145+
<Style.Triggers>
146+
<Trigger Property="NavigationUIVisibility"
147+
Value="Visible">
148+
<Setter Property="Template"
149+
Value="{StaticResource FrameNavChromeTemplateKey}"/>
150+
</Trigger>
151+
<MultiTrigger>
152+
<MultiTrigger.Conditions>
153+
<Condition Property="JournalOwnership"
154+
Value="OwnsJournal"/>
155+
<Condition Property="NavigationUIVisibility"
156+
Value="Automatic"/>
157+
</MultiTrigger.Conditions>
158+
<Setter Property="Template"
159+
Value="{StaticResource FrameNavChromeTemplateKey}"/>
160+
</MultiTrigger>
161+
</Style.Triggers>
17162
</Style>
18163

164+
19165
</ResourceDictionary>

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
99

1010
<Style x:Key="DefaultPageStyle" TargetType="{x:Type Page}">
11-
<Setter Property="Control.Foreground">
11+
<Setter Property="TextElement.Foreground">
1212
<Setter.Value>
1313
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
1414
</Setter.Value>
1515
</Setter>
1616
<Setter Property="Background" Value="Transparent" />
17-
<!-- The Display option casues a large aliasing effect -->
18-
<!-- <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" /> -->
1917
<Setter Property="Focusable" Value="False" />
2018
<Setter Property="SnapsToDevicePixels" Value="True" />
2119
<Setter Property="OverridesDefaultStyle" Value="True" />
@@ -26,8 +24,8 @@
2624
<ContentPresenter
2725
HorizontalAlignment="Stretch"
2826
VerticalAlignment="Stretch"
29-
Content="{TemplateBinding ContentControl.Content}"
30-
TextElement.Foreground="{TemplateBinding Control.Foreground}" />
27+
Content="{TemplateBinding Page.Content}"
28+
TextElement.Foreground="{TemplateBinding TextElement.Foreground}" />
3129
</Grid>
3230
</ControlTemplate>
3331
</Setter.Value>

0 commit comments

Comments
 (0)