[PTRun]Update the code for .NET 9.0.1 - remove workarounds (#36909)

* Revove some unneeded changes after pdating to .net9.1
This commit is contained in:
Ionuț Manța
2025-01-17 06:47:24 -08:00
committed by GitHub
parent 41803cc632
commit e7abd34778
6 changed files with 11 additions and 6916 deletions

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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