diff --git a/src/Controls/src/Core/Application/Application.Windows.cs b/src/Controls/src/Core/Application/Application.Windows.cs index 261b6771c807..9db4bb068df8 100644 --- a/src/Controls/src/Core/Application/Application.Windows.cs +++ b/src/Controls/src/Core/Application/Application.Windows.cs @@ -1,6 +1,153 @@ -namespace Microsoft.Maui.Controls +using System; +using Microsoft.Maui.ApplicationModel; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using Windows.UI; + +namespace Microsoft.Maui.Controls { public partial class Application { + AppTheme? _currentThemeForWindows; + + partial void OnRequestedThemeChangedPlatform(AppTheme newTheme) + { + _currentThemeForWindows = newTheme; + + ApplyThemeToAllWindows(newTheme, UserAppTheme == AppTheme.Unspecified); + } + + partial void OnPlatformWindowAdded(Window window) + { + window.HandlerChanged += OnWindowHandlerChanged; + + if (_currentThemeForWindows is not null && window.Handler is not null) + { + TryApplyThemeToWindow(window); + } + } + + partial void OnPlatformWindowRemoved(Window window) + { + window.HandlerChanged -= OnWindowHandlerChanged; + } + + void OnWindowHandlerChanged(object? sender, EventArgs e) + { + if (sender is Window window) + { + TryApplyThemeToWindow(window); + } + } + + void TryApplyThemeToWindow(Window window) + { + if (_currentThemeForWindows is AppTheme theme) + { + var forcedElementTheme = GetElementTheme(); + + if (IsWindowReady(window)) + { + ApplyThemeToWindow(window, UserAppTheme == AppTheme.Unspecified, forcedElementTheme); + } + } + } + + bool IsWindowReady(Window window) + { + var platformWindow = window?.Handler?.PlatformView as UI.Xaml.Window; + return platformWindow?.Content is FrameworkElement; + } + + void ApplyThemeToAllWindows(AppTheme newTheme, bool followSystem) + { + var forcedElementTheme = GetElementTheme(); + + foreach (var window in Windows) + { + if (IsWindowReady(window)) + { + ApplyThemeToWindow(window, followSystem, forcedElementTheme); + } + } + } + + ElementTheme GetElementTheme() + { + if (_currentThemeForWindows is AppTheme theme) + { + return theme switch + { + AppTheme.Dark => ElementTheme.Dark, + AppTheme.Light => ElementTheme.Light, + _ => ElementTheme.Default + }; + } + return ElementTheme.Default; + } + + void ApplyThemeToWindow(Window? window, bool followSystem, ElementTheme forcedElementTheme) + { + var platformWindow = window?.Handler?.PlatformView as UI.Xaml.Window; + + if (platformWindow is null) + { + System.Diagnostics.Debug.WriteLine("ApplyThemeToWindow: platformWindow is null. Unable to apply theme to the root element."); + return; + } + + if (platformWindow.DispatcherQueue is null) + { + System.Diagnostics.Debug.WriteLine("ApplyThemeToWindow: platformWindow.DispatcherQueue is null. Unable to apply theme to the root element."); + return; + } + + platformWindow.DispatcherQueue.TryEnqueue(() => + { + if (platformWindow.Content is not FrameworkElement root) + { + return; + } + + // Setting RequestedTheme on the root element automatically applies the theme to all child controls. + root.RequestedTheme = followSystem ? ElementTheme.Default : forcedElementTheme; + + var isDark = followSystem + ? (UI.Xaml.Application.Current.RequestedTheme == ApplicationTheme.Dark) + : (forcedElementTheme == ElementTheme.Dark); + + SetTitleBarButtonColors(platformWindow, isDark); + }); + } + + void SetTitleBarButtonColors(UI.Xaml.Window platformWindow, bool isDark) + { + // Color references: + // https://github.com/microsoft/WinUI-Gallery/blob/main/WinUIGallery/Helpers/TitleBarHelper.cs + // https://github.com/dotnet/maui/blob/main/src/Core/src/Platform/Windows/MauiWinUIWindow.cs#L218 + if (AppWindowTitleBar.IsCustomizationSupported()) + { + var titleBar = platformWindow.GetAppWindow()?.TitleBar; + if (titleBar is not null) + { + titleBar.ButtonBackgroundColor = UI.Colors.Transparent; + titleBar.ButtonInactiveBackgroundColor = UI.Colors.Transparent; + titleBar.ButtonHoverBackgroundColor = isDark ? TitleBarColors.DarkHoverBackground : TitleBarColors.LightHoverBackground; + titleBar.ButtonPressedBackgroundColor = isDark ? TitleBarColors.DarkPressedBackground : TitleBarColors.LightPressedBackground; + titleBar.ButtonHoverForegroundColor = isDark ? TitleBarColors.DarkForeground : TitleBarColors.LightForeground; + titleBar.ButtonPressedForegroundColor = isDark ? TitleBarColors.DarkForeground : TitleBarColors.LightForeground; + titleBar.ButtonForegroundColor = isDark ? TitleBarColors.DarkForeground : TitleBarColors.LightForeground; + } + } + } + } + static class TitleBarColors + { + public static readonly Color LightHoverBackground = UI.ColorHelper.FromArgb(24, 0, 0, 0); + public static readonly Color DarkHoverBackground = UI.ColorHelper.FromArgb(24, 255, 255, 255); + public static readonly Color LightPressedBackground = UI.ColorHelper.FromArgb(31, 0, 0, 0); + public static readonly Color DarkPressedBackground = UI.ColorHelper.FromArgb(31, 255, 255, 255); + public static readonly Color LightForeground = UI.Colors.Black; + public static readonly Color DarkForeground = UI.Colors.White; } } \ No newline at end of file diff --git a/src/Controls/src/Core/Application/Application.cs b/src/Controls/src/Core/Application/Application.cs index 5921d2fe15d3..254eb46274fd 100644 --- a/src/Controls/src/Core/Application/Application.cs +++ b/src/Controls/src/Core/Application/Application.cs @@ -262,6 +262,11 @@ void TriggerThemeChangedActual() _lastAppTheme = newTheme; OnPropertyChanged(nameof(UserAppTheme)); +#if WINDOWS + // Notify platform so it can apply the correct UI theme + OnRequestedThemeChangedPlatform(newTheme); +#endif + OnParentResourcesChanged([new KeyValuePair(AppThemeBinding.AppThemeResource, newTheme)]); _weakEventManager.HandleEvent(this, new AppThemeChangedEventArgs(newTheme), nameof(RequestedThemeChanged)); } @@ -271,6 +276,10 @@ void TriggerThemeChangedActual() } } +#if WINDOWS + partial void OnRequestedThemeChangedPlatform(AppTheme newTheme); +#endif + public event EventHandler? ModalPopped; public event EventHandler? ModalPopping; @@ -498,6 +507,10 @@ internal void RemoveWindow(Window window) } _windows.Remove(window); + +#if WINDOWS + OnPlatformWindowRemoved(window); +#endif } public virtual void OpenWindow(Window window) @@ -571,6 +584,16 @@ internal void AddWindow(Window window) // up to the window before triggering any down stream life cycle // events. window.FinishedAddingWindowToApplication(this); + +#if WINDOWS + OnPlatformWindowAdded(window); +#endif } + +#if WINDOWS + // Windows-specific hook implemented in Application.Windows.cs + partial void OnPlatformWindowAdded(Window window); + partial void OnPlatformWindowRemoved(Window window); +#endif } } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue22058.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue22058.cs new file mode 100644 index 000000000000..6843ef93e0e7 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue22058.cs @@ -0,0 +1,82 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 22058, "[Windows] OS system components ignore app theme", PlatformAffected.UWP)] +public class Issue22058 : ContentPage +{ + TitleBar customTitleBar; + + public Issue22058() + { + this.SetAppThemeColor(BackgroundProperty, Colors.White, Colors.Black); + customTitleBar = new TitleBar + { + Title = "MauiApp1", + Subtitle = "Welcome to .NET MAUI", + HeightRequest = 32 + }; + + var button = new Button + { + Text = "Change To Dark User App Theme", + AutomationId = "ThemeChangeButton", + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Start, + }; + + button.Clicked += (sender, e) => + { + if (Application.Current is not null) + { + Application.Current.UserAppTheme = AppTheme.Dark; + } + }; + + var resetThemeButton = new Button + { + Text = "Reset User App Theme", + AutomationId = "ResetThemeButton", + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Start, + }; + + resetThemeButton.Clicked += (sender, e) => + { + if (Application.Current is not null) + { + Application.Current.UserAppTheme = AppTheme.Unspecified; + } + }; + + var timePicker = new TimePicker + { + VerticalOptions = LayoutOptions.Center, + AutomationId = "TimePickerControl", + HorizontalOptions = LayoutOptions.Center, + }; + + var verticalStackLayout = new VerticalStackLayout() + { + Spacing = 20, + Padding = new Thickness(20), + }; + + verticalStackLayout.Add(button); + verticalStackLayout.Add(resetThemeButton); + verticalStackLayout.Add(timePicker); + + Content = verticalStackLayout; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + if (Window is not null) + { + Window.TitleBar = customTitleBar; + } + else if (Shell.Current?.Window is not null) + { + Shell.Current.Window.TitleBar = customTitleBar; + } + } +} diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTimePickerTheme.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTimePickerTheme.png new file mode 100644 index 000000000000..9735076f5f04 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTimePickerTheme.png differ diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTitleBarBackgroundColorChange.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTitleBarBackgroundColorChange.png new file mode 100644 index 000000000000..1320361afa97 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTitleBarBackgroundColorChange.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22058.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22058.cs new file mode 100644 index 000000000000..e6cc15805ed0 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22058.cs @@ -0,0 +1,55 @@ +#if WINDOWS || MACCATALYST // TitleBar is only supported on Windows and MacCatalyst +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue22058 : _IssuesUITest +{ + public override string Issue => "[Windows] OS system components ignore app theme"; + + public Issue22058(TestDevice device) + : base(device) + { } + + [Test, Order(1)] + [Category(UITestCategories.TitleView)] + public async Task VerifyTitleBarBackgroundColorChange() + { + try + { + App.WaitForElement("ThemeChangeButton"); + App.Tap("ThemeChangeButton"); + await Task.Delay(1000); // Slight delay to apply the theme change + VerifyScreenshot(includeTitleBar: true); + } + finally + { + App.Tap("ResetThemeButton"); + } + } + + [Test, Order(2)] + [Category(UITestCategories.TitleView)] + public async Task VerifyTimePickerTheme() + { + try + { + App.WaitForElement("ThemeChangeButton"); + App.Tap("ThemeChangeButton"); + await Task.Delay(1000); // Slight delay to apply the theme change + +#if WINDOWS // TimePicker pop up is only supported on Windows + App.Tap("TimePickerControl"); +#endif + VerifyScreenshot(includeTitleBar: true); + } + finally + { + App.TapCoordinates(50, 50); + App.Tap("ResetThemeButton"); + } + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_CheckBox_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_CheckBox_VerifyVisualState.png index 745195008de7..9a98037d32b6 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_CheckBox_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_CheckBox_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_DatePicker_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_DatePicker_VerifyVisualState.png index 6d6606160ea0..2553c90b16a3 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_DatePicker_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_DatePicker_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EditorAndPlaceholderColor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EditorAndPlaceholderColor_VerifyVisualState.png index 4b29334a3a48..47d57191abd5 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EditorAndPlaceholderColor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EditorAndPlaceholderColor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Editor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Editor_VerifyVisualState.png index c551c82cacfb..903c0dac1c75 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Editor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Editor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EntryAndPlaceholderColor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EntryAndPlaceholderColor_VerifyVisualState.png index bec2dae77a28..889ba7378f82 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EntryAndPlaceholderColor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_EntryAndPlaceholderColor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Picker_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Picker_VerifyVisualState.png index 67aa839ae85f..6c9c5fa75049 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Picker_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Picker_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_RadioButton_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_RadioButton_VerifyVisualState.png index 8d78fdb81ca9..76788db87a94 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_RadioButton_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_RadioButton_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png index e66b2a322478..f6c71f4eb23e 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBar_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBar_VerifyVisualState.png index 71c6ab7c3609..74c45d55773c 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBar_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_SearchBar_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Slider_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Slider_VerifyVisualState.png index 1da609988947..c1b51aa9d894 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Slider_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Slider_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Switch_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Switch_VerifyVisualState.png index eda5878011c3..1c37bc269263 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Switch_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_Switch_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_VerifyVisualState.png index d7266f47677f..fe52b7d5dfd4 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DarkTheme_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EditorAndEntryInputFieldsShouldChangeColorsOnAppThemeChange.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EditorAndEntryInputFieldsShouldChangeColorsOnAppThemeChange.png index 72d012e964fc..622f8349001a 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EditorAndEntryInputFieldsShouldChangeColorsOnAppThemeChange.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EditorAndEntryInputFieldsShouldChangeColorsOnAppThemeChange.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorPlaceholderTextColorAppThemeBindingUpdatesOnDarkTheme.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorPlaceholderTextColorAppThemeBindingUpdatesOnDarkTheme.png index a4d66c8ef4e2..d3809be17654 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorPlaceholderTextColorAppThemeBindingUpdatesOnDarkTheme.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorPlaceholderTextColorAppThemeBindingUpdatesOnDarkTheme.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorTextColorAppThemeBindingUpdatesOnDarkTheme.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorTextColorAppThemeBindingUpdatesOnDarkTheme.png index 5c252be3cdad..6d561321dbe9 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorTextColorAppThemeBindingUpdatesOnDarkTheme.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryAndEditorTextColorAppThemeBindingUpdatesOnDarkTheme.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonColorShouldUpdateOnThemeChange.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonColorShouldUpdateOnThemeChange.png index 7e05cd60da58..44699edbcd24 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonColorShouldUpdateOnThemeChange.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonColorShouldUpdateOnThemeChange.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_DatePicker_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_DatePicker_VerifyVisualState.png index ae339d051f48..b51363dbb9e2 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_DatePicker_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_DatePicker_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EditorAndPlaceholderColor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EditorAndPlaceholderColor_VerifyVisualState.png index 8029d3c364b2..e228b892affa 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EditorAndPlaceholderColor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EditorAndPlaceholderColor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Editor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Editor_VerifyVisualState.png index 23f1334267d5..d722fea1b28f 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Editor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Editor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EntryAndPlaceholderColor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EntryAndPlaceholderColor_VerifyVisualState.png index 883c1c93e22c..61a583178c1f 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EntryAndPlaceholderColor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_EntryAndPlaceholderColor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Picker_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Picker_VerifyVisualState.png index eeaf2894f5e0..31c6afefe6f9 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Picker_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Picker_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_RadioButton_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_RadioButton_VerifyVisualState.png index bf5886210161..8d9f414fd259 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_RadioButton_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_RadioButton_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png index 97d679cf10dd..b04ff4391ce4 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBarAndPlaceholderColor_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBar_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBar_VerifyVisualState.png index ad2bd5cb6960..3874e80eace0 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBar_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_SearchBar_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Slider_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Slider_VerifyVisualState.png index e2d0d217cf2f..8dcb4dd4d389 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Slider_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Slider_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Switch_VerifyVisualState.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Switch_VerifyVisualState.png index 8e103990f16b..56f81a4b3c66 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Switch_VerifyVisualState.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/LightTheme_Switch_VerifyVisualState.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/PlaceholderColorShouldChange.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/PlaceholderColorShouldChange.png index b79711069da8..0f2e42aa0244 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/PlaceholderColorShouldChange.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/PlaceholderColorShouldChange.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SearchbarColorsShouldUpdate.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SearchbarColorsShouldUpdate.png index df6bf62b627f..be6751bb9b3d 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SearchbarColorsShouldUpdate.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SearchbarColorsShouldUpdate.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemsShouldBeVisible.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemsShouldBeVisible.png index c1eee414892d..7033724d9658 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemsShouldBeVisible.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemsShouldBeVisible.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySwitchOffColorAfterTogglingDarkTheme.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySwitchOffColorAfterTogglingDarkTheme.png index 8626bb7001eb..fccfffddb836 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySwitchOffColorAfterTogglingDarkTheme.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySwitchOffColorAfterTogglingDarkTheme.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTimePickerTheme.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTimePickerTheme.png new file mode 100644 index 000000000000..753a47eacad3 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTimePickerTheme.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTitleBarBackgroundColorChange.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTitleBarBackgroundColorChange.png new file mode 100644 index 000000000000..27951412c438 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTitleBarBackgroundColorChange.png differ diff --git a/src/Core/src/Platform/Windows/MauiWinUIWindow.cs b/src/Core/src/Platform/Windows/MauiWinUIWindow.cs index ad9b3461baf4..4993b9e5d10a 100644 --- a/src/Core/src/Platform/Windows/MauiWinUIWindow.cs +++ b/src/Core/src/Platform/Windows/MauiWinUIWindow.cs @@ -45,7 +45,7 @@ public MauiWinUIWindow() titleBar.ExtendsContentIntoTitleBar = true; } - _viewSettings.ColorValuesChanged += _viewSettings_ColorValuesChanged; + _viewSettings.ColorValuesChanged += ViewSettingsColorValuesChanged; SetTileBarButtonColors(); } @@ -66,20 +66,26 @@ protected virtual void OnActivated(object sender, UI.Xaml.WindowActivatedEventAr // when maximizing a window // https://github.com/microsoft/microsoft-ui-xaml/issues/7343 if (_isActivated) + { return; + } _isActivated = true; if (_enableResumeEvent) + { Services?.InvokeLifecycleEvents(del => del(this)); + } else + { _enableResumeEvent = true; + } } else if (args.WindowActivationState == UI.Xaml.WindowActivationState.Deactivated && !_isActivated) { // Don't invoke deactivated event if we're not activated. It's possible we can - // recieve this event multiple times if we start a new child process and that + // receive this event multiple times if we start a new child process and that // process creates a new window return; } @@ -91,14 +97,14 @@ protected virtual void OnActivated(object sender, UI.Xaml.WindowActivatedEventAr Services?.InvokeLifecycleEvents(del => del(this, args)); } - private void OnClosedPrivate(object sender, UI.Xaml.WindowEventArgs args) + void OnClosedPrivate(object sender, UI.Xaml.WindowEventArgs args) { OnClosed(sender, args); Activated -= OnActivated; Closed -= OnClosedPrivate; VisibilityChanged -= OnVisibilityChanged; - _viewSettings.ColorValuesChanged -= _viewSettings_ColorValuesChanged; + _viewSettings.ColorValuesChanged -= ViewSettingsColorValuesChanged; if (_windowIcon != IntPtr.Zero) { @@ -174,7 +180,7 @@ void OnWindowMessage(object? sender, WindowMessageEventArgs e) bool hasTitleBar = PlatformMethods.HasStyle(styleChange.StyleNew, PlatformMethods.WindowStyles.WS_CAPTIONANDSYSTEMMENU); var rootManager = Window?.Handler?.MauiContext?.GetNavigationRootManager(); - if (rootManager != null) + if (rootManager is not null) { rootManager?.SetTitleBarVisibility(hasTitleBar); } @@ -189,7 +195,7 @@ void OnWindowMessage(object? sender, WindowMessageEventArgs e) /// /// Default the Window Icon to the icon stored in the .exe, if any. /// - /// The Icon can be overriden by callers by calling SetIcon themselves. + /// The Icon can be overridden by callers by calling SetIcon themselves. /// void SetIcon() { @@ -210,24 +216,24 @@ void SetIcon() } } - private void _viewSettings_ColorValuesChanged(ViewManagement.UISettings sender, object args) + void ViewSettingsColorValuesChanged(ViewManagement.UISettings sender, object args) { DispatcherQueue.TryEnqueue(SetTileBarButtonColors); } - private void SetTileBarButtonColors() + void SetTileBarButtonColors() { if (AppWindowTitleBar.IsCustomizationSupported()) { var titleBar = this.GetAppWindow()?.TitleBar; if (titleBar is null) + { return; + } titleBar.ButtonBackgroundColor = Colors.Transparent; titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; - titleBar.ButtonForegroundColor = UI.Xaml.Application.Current.RequestedTheme == UI.Xaml.ApplicationTheme.Dark ? - Colors.White : Colors.Black; } }