Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Enabling Fluent as default theme using an opt-in and app.config #9332

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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 @@ -50,6 +50,34 @@ CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVi
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Style.TargetType' changed from '[LocalizabilityAttribute(17)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]' in the implementation.
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Style.Triggers' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.StyleTypedPropertyAttribute' changed from '[AttributeUsageAttribute(4, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]' in the implementation.
MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColor.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorBrush.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorBrushKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorDark1.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorDark1Brush.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark1BrushKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark1Key.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorDark2.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorDark2Brush.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark2BrushKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark2Key.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorDark3.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorDark3Brush.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark3BrushKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark3Key.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorLight1.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorLight1Brush.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight1BrushKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight1Key.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorLight2.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorLight2Brush.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight2BrushKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight2Key.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorLight3.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorLight3Brush.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight3BrushKey.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight3Key.get()' does not exist in the implementation but it does exist in the contract.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.TemplatePartAttribute' changed from '[AttributeUsageAttribute(4, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]' in the implementation.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.TemplateVisualStateAttribute' changed from '[AttributeUsageAttribute(4, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]' in the implementation.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.ThemeInfoAttribute' changed from '[AttributeUsageAttribute(1)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Assembly)]' in the implementation.
Expand Down Expand Up @@ -262,4 +290,4 @@ CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVi
CannotChangeAttribute : Attribute 'System.Windows.Markup.DesignerSerializationOptionsAttribute' on 'System.Windows.Markup.XmlAttributeProperties.GetXmlSpace(System.Windows.DependencyObject)' changed from '[DesignerSerializationOptionsAttribute(1)]' in the contract to '[DesignerSerializationOptionsAttribute(DesignerSerializationOptions.SerializeAsAttribute)]' in the implementation.
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Media.Animation.Storyboard.GetTarget(System.Windows.DependencyObject)' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Shapes.Shape' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation.
Total Issues: 263
Total Issues: 291
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ public static bool DisableFluentThemeWindowBackdrop
return LocalAppContext.GetCachedSwitchValue(DisableFluentThemeWindowBackdropSwitchName, ref _DisableFluentThemeWindowBackdrop);
}
}


// Switch to enable Fluent theme in WPF
internal const string EnableFluentThemeSwitchName = "Switch.System.Windows.Appearance.EnableFluentTheme";
private static int _EnableFluentTheme;
public static bool EnableFluentTheme
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return LocalAppContext.GetCachedSwitchValue(EnableFluentThemeSwitchName, ref _EnableFluentTheme);
}
}
}

#pragma warning restore 436
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ private static void GetThemeNameAndColor(out string themeName, out string themeC
themeName = "Aero2";
}

NameValueCollection appSettings = null;
#if DEBUG
// for debugging, config file can override the theme name
NameValueCollection appSettings = null;
try
{
appSettings = ConfigurationManager.AppSettings;
Expand All @@ -297,6 +297,38 @@ private static void GetThemeNameAndColor(out string themeName, out string themeC
#endif

themeColor = themeColorSB.ToString();

if (FrameworkAppContextSwitches.EnableFluentTheme)
{
themeName = "Fluent";
themeColor = ThemeManager.IsSystemThemeLight() ? "Light" : "Dark";

appSettings = null;
try
{
appSettings = ConfigurationManager.AppSettings;
}
catch (ConfigurationErrorsException)
{
}

if (appSettings != null)
{
string tc = appSettings["ThemeColorOverride"];
if (!String.IsNullOrEmpty(tc))
{
switch(tc.ToLowerInvariant())
{
case "light":
case "dark":
themeColor = tc;
ThemeManager.OverrideThemeColor(themeColor);
break;
}
themeColor = tc;
}
}
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ private static void InitializeNetFxSwitchDefaultsForNetCoreRuntime()
LocalAppContext.DefineSwitchDefault(FrameworkAppContextSwitches.AppendLocalAssemblyVersionForSourceUriSwitchName, false);
LocalAppContext.DefineSwitchDefault(FrameworkAppContextSwitches.KeyboardNavigationFromHyperlinkInItemsControlIsNotRelativeToFocusedElementSwitchName, false);
LocalAppContext.DefineSwitchDefault(FrameworkAppContextSwitches.ItemAutomationPeerKeepsItsItemAliveSwitchName, false);

LocalAppContext.DefineSwitchDefault(FrameworkAppContextSwitches.EnableFluentThemeSwitchName, true);
LocalAppContext.DefineSwitchDefault(FrameworkAppContextSwitches.DisableFluentThemeWindowBackdropSwitchName, false);

// UseAdornerForTextboxSelectionRenderingSwitchName is always true, i.e., disabled by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private static bool UpdateGlassFrame(IntPtr hwnd, WindowBackdropType backdropTyp
#region Internal Properties

internal static bool IsBackdropEnabled => _isBackdropEnabled ??= Utility.IsWindows11_22H2OrNewer &&
ThemeManager.IsFluentThemeEnabled &&
(ThemeManager.IsFluentThemeEnabled ||
FrameworkAppContextSwitches.EnableFluentTheme) &&
!FrameworkAppContextSwitches.DisableFluentThemeWindowBackdrop;

private static bool? _isBackdropEnabled = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ internal static Color CurrentApplicationAccentColor
get { return _currentApplicationAccentColor; }
}

static DwmColorization()
{
UpdateCachedAccentColors();
}


#region Accent Colors Properties

internal static Color AccentColor
{
get { return _currentApplicationAccentColor; }
}

internal static Color AccentColorLight1 { get; set; }
internal static Color AccentColorLight2 { get; set; }
internal static Color AccentColorLight3 { get; set; }
internal static Color AccentColorDark1 { get; set; }
internal static Color AccentColorDark2 { get; set; }
internal static Color AccentColorDark3 { get; set; }

#endregion

internal static UISettings _UISettings
{
get
Expand Down Expand Up @@ -51,7 +73,6 @@ internal static Color GetSystemAccentColor()
internal static void UpdateAccentColors()
{
Color systemAccent = GetSystemAccentColor();
Color primaryAccent, secondaryAccent, tertiaryAccent;

if (systemAccent != _currentApplicationAccentColor)
{
Expand All @@ -61,19 +82,46 @@ internal static void UpdateAccentColors()
if (ThemeManager.IsSystemThemeLight())
{
// In light mode, we use darker shades of the accent color
primaryAccent = _UISettings.AccentDark1;
secondaryAccent = _UISettings.AccentDark2;
tertiaryAccent = _UISettings.AccentDark3;
AccentColorDark1 = _UISettings.AccentDark1;
AccentColorDark2 = _UISettings.AccentDark2;
AccentColorDark3 = _UISettings.AccentDark3;
}
else
{
// In dark mode, we use lighter shades of the accent color
AccentColorLight1 = _UISettings.AccentLight1;
AccentColorLight2 = _UISettings.AccentLight2;
AccentColorLight3 = _UISettings.AccentLight3;
}

UpdateColorResources(systemAccent, AccentColorLight1, AccentColorLight2, AccentColorLight3);
_currentApplicationAccentColor = systemAccent;
}

internal static void UpdateCachedAccentColors()
{
Color systemAccent = GetSystemAccentColor();

if (systemAccent != _currentApplicationAccentColor)
{
_UISettings.TryUpdateAccentColors();
}

if (ThemeManager.IsSystemThemeLight())
{
// In light mode, we use darker shades of the accent color
AccentColorDark1 = _UISettings.AccentDark1;
AccentColorDark2 = _UISettings.AccentDark2;
AccentColorDark3 = _UISettings.AccentDark3;
}
else
{
// In dark mode, we use lighter shades of the accent color
primaryAccent = _UISettings.AccentLight1;
secondaryAccent = _UISettings.AccentLight2;
tertiaryAccent = _UISettings.AccentLight3;
AccentColorLight1 = _UISettings.AccentLight1;
AccentColorLight2 = _UISettings.AccentLight2;
AccentColorLight3 = _UISettings.AccentLight3;
}

UpdateColorResources(systemAccent, primaryAccent, secondaryAccent, tertiaryAccent);
_currentApplicationAccentColor = systemAccent;
}

Expand All @@ -86,27 +134,9 @@ private static void UpdateColorResources(
Color secondaryAccent,
Color tertiaryAccent)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("INFO | SystemAccentColor: " + systemAccent, "System.Windows.Accent");
System
.Diagnostics
.Debug
.WriteLine("INFO | SystemAccentColorPrimary: " + primaryAccent, "System.Windows.Accent");
System
.Diagnostics
.Debug
.WriteLine("INFO | SystemAccentColorSecondary: " + secondaryAccent, "System.Windows.Accent");
System
.Diagnostics
.Debug
.WriteLine("INFO | SystemAccentColorTertiary: " + tertiaryAccent, "System.Windows.Accent");
#endif

if (!ThemeManager.IsSystemThemeLight())
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("INFO | Text on accent is DARK", "System.Windows.Accent");
#endif
Application.Current.Resources["TextOnAccentFillColorPrimary"] =
Color.FromArgb( 0xFF, 0x00, 0x00, 0x00);

Expand All @@ -124,9 +154,6 @@ private static void UpdateColorResources(
}
else
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("INFO | Text on accent is LIGHT", "System.Windows.Accent");
#endif
Application.Current.Resources["TextOnAccentFillColorPrimary"] =
Color.FromArgb( 0xFF, 0xFF, 0xFF, 0xFF);

Expand Down
Loading
Loading