From e7abd347789e5674485bce6c964693a747fc0f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Man=C8=9Ba?= Date: Fri, 17 Jan 2025 06:47:24 -0800 Subject: [PATCH] [PTRun]Update the code for .NET 9.0.1 - remove workarounds (#36909) * Revove some unneeded changes after pdating to .net9.1 --- src/modules/launcher/PowerLauncher/App.xaml | 1 + .../Helper/AnimationFactorToValueConverter.cs | 45 - .../Helper/FallbackBrushConverter.cs | 44 - .../PowerLauncher/Helper/ThemeManager.cs | 34 +- .../PowerLauncher/Styles/FluentHC.xaml | 6710 ----------------- .../launcher/PowerLauncher/Styles/Styles.xaml | 93 +- 6 files changed, 11 insertions(+), 6916 deletions(-) delete mode 100644 src/modules/launcher/PowerLauncher/Helper/AnimationFactorToValueConverter.cs delete mode 100644 src/modules/launcher/PowerLauncher/Helper/FallbackBrushConverter.cs delete mode 100644 src/modules/launcher/PowerLauncher/Styles/FluentHC.xaml diff --git a/src/modules/launcher/PowerLauncher/App.xaml b/src/modules/launcher/PowerLauncher/App.xaml index 052ea24ea0..23871bda7f 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml +++ b/src/modules/launcher/PowerLauncher/App.xaml @@ -8,6 +8,7 @@ + diff --git a/src/modules/launcher/PowerLauncher/Helper/AnimationFactorToValueConverter.cs b/src/modules/launcher/PowerLauncher/Helper/AnimationFactorToValueConverter.cs deleted file mode 100644 index 3987f1c3bf..0000000000 --- a/src/modules/launcher/PowerLauncher/Helper/AnimationFactorToValueConverter.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Controls/AnimationFactorToValueConverter.cs -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Data; - -#pragma warning disable IDE0130 // Namespace does not match folder structure -namespace Fluent.Controls -#pragma warning restore IDE0130 // Namespace does not match folder structure -{ - internal sealed class AnimationFactorToValueConverter : IMultiValueConverter - { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - { - if (values[0] is not double completeValue) - { - return 0.0; - } - - if (values[1] is not double factor) - { - return 0.0; - } - - if (parameter is "negative") - { - factor = -factor; - } - - return factor * completeValue; - } - - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/modules/launcher/PowerLauncher/Helper/FallbackBrushConverter.cs b/src/modules/launcher/PowerLauncher/Helper/FallbackBrushConverter.cs deleted file mode 100644 index a9e3b06a80..0000000000 --- a/src/modules/launcher/PowerLauncher/Helper/FallbackBrushConverter.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Copied from https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Controls/FallbackBrushConverter.cs -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using System.Windows.Data; - -using System.Windows.Media; - -#pragma warning disable IDE0130 // Namespace does not match folder structure -namespace Fluent.Controls -#pragma warning restore IDE0130 // Namespace does not match folder structure -{ - internal sealed class FallbackBrushConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is SolidColorBrush brush) - { - return brush; - } - - if (value is Color color) - { - return new SolidColorBrush(color); - } - - // We draw red to visibly see an invalid bind in the UI. - return Brushes.Red; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/modules/launcher/PowerLauncher/Helper/ThemeManager.cs b/src/modules/launcher/PowerLauncher/Helper/ThemeManager.cs index 4f7ff85b47..66a71b5b0a 100644 --- a/src/modules/launcher/PowerLauncher/Helper/ThemeManager.cs +++ b/src/modules/launcher/PowerLauncher/Helper/ThemeManager.cs @@ -36,37 +36,20 @@ namespace PowerLauncher.Helper { if (e.Category == UserPreferenceCategory.General) { - // When switching from high contrast to dark mode we have to use UserPreferenceCategory.General otherwise it will crash when loading fluent.xaml UpdateTheme(); } - else if (e.Category == UserPreferenceCategory.Color) - { - // https://github.com/dotnet/wpf/issues/10043 When switching to high contrast we have to use UserPreferenceCategory.Color or it will crash due to fluent.xaml being already loaded. - if (_currentTheme is ManagedCommon.Theme.Dark or ManagedCommon.Theme.Light) - { - UpdateTheme(); - } - } } private void SetSystemTheme(ManagedCommon.Theme theme) { _mainWindow.Background = OSVersionHelper.IsWindows11() is false ? SystemColors.WindowBrush : null; - _mainWindow.Resources.MergedDictionaries.Clear(); - _mainWindow.Resources.MergedDictionaries.Add(new ResourceDictionary - { - Source = new Uri("Styles/Styles.xaml", UriKind.Relative), - }); + // Need to disable WPF0001 since setting Application.Current.ThemeMode is experimental + // https://learn.microsoft.com/en-us/dotnet/desktop/wpf/whats-new/net90#set-in-code +#pragma warning disable WPF0001 + Application.Current.ThemeMode = theme is ManagedCommon.Theme.Light ? ThemeMode.Light : ThemeMode.Dark; if (theme is ManagedCommon.Theme.Dark or ManagedCommon.Theme.Light) { - string themeString = theme == ManagedCommon.Theme.Light ? "pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.Light.xaml" - : "pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.Dark.xaml"; - ResourceDictionary fluentThemeDictionary = new() - { - Source = new Uri(themeString, UriKind.Absolute), - }; - _mainWindow.Resources.MergedDictionaries.Add(fluentThemeDictionary); if (!OSVersionHelper.IsWindows11()) { // Apply background only on Windows 10 @@ -79,10 +62,6 @@ namespace PowerLauncher.Helper } else { - _mainWindow.Resources.MergedDictionaries.Add(new ResourceDictionary - { - Source = new Uri("Styles/FluentHC.xaml", UriKind.Relative), - }); string styleThemeString = theme switch { ManagedCommon.Theme.Light => "Themes/Light.xaml", @@ -92,10 +71,15 @@ namespace PowerLauncher.Helper ManagedCommon.Theme.HighContrastWhite => "Themes/HighContrastWhite.xaml", _ => "Themes/HighContrastBlack.xaml", }; + _mainWindow.Resources.MergedDictionaries.Clear(); _mainWindow.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(styleThemeString, UriKind.Relative), }); + ResourceDictionary test = new ResourceDictionary + { + Source = new Uri(styleThemeString, UriKind.Relative), + }; if (OSVersionHelper.IsWindows11()) { // Apply background only on Windows 11 to keep the same style as WPFUI diff --git a/src/modules/launcher/PowerLauncher/Styles/FluentHC.xaml b/src/modules/launcher/PowerLauncher/Styles/FluentHC.xaml deleted file mode 100644 index 91fc2b6d1f..0000000000 --- a/src/modules/launcher/PowerLauncher/Styles/FluentHC.xaml +++ /dev/null @@ -1,6710 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 11,5,11,6 - 1 - 8,0,0,0 - 14 - 22 - 22 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 12 - 20 - - 1 - 8,6,0,0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 12 - 14 - 20 - 28 - 40 - 68 - - - - - - - - 1,1,1,1 - 0,0,0,1 - 10,0,0,0 - 0,0,10,0 - 0,0,4,0 - 0,0,0,0 - 24 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 9,6,9,8 - 320 - 1 - - - - - - - - - - - - - - + 16