From 25c6b3f135efc62566d7268671053954ba52a7b5 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Fri, 7 Mar 2025 15:07:53 +0100 Subject: [PATCH 1/4] Move helpers out of App.xaml.cs --- WinUIGallery/App.xaml.cs | 54 ++----------------- WinUIGallery/Helpers/EnumHelper.cs | 22 ++++++++ WinUIGallery/Helpers/ThemeHelper.cs | 4 +- WinUIGallery/Helpers/VersionHelper.cs | 35 ++++++++++++ WinUIGallery/Pages/HomePage.xaml.cs | 2 +- WinUIGallery/Pages/SettingsPage.xaml.cs | 4 +- .../Samples/ControlPages/TitleBarPage.xaml.cs | 2 +- 7 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 WinUIGallery/Helpers/EnumHelper.cs create mode 100644 WinUIGallery/Helpers/VersionHelper.cs diff --git a/WinUIGallery/App.xaml.cs b/WinUIGallery/App.xaml.cs index a39a23bd9..2bf88d799 100644 --- a/WinUIGallery/App.xaml.cs +++ b/WinUIGallery/App.xaml.cs @@ -10,20 +10,16 @@ using System; using System.Diagnostics; using System.Linq; -using System.Reflection; -using WinUIGallery.Models; -using WinUIGallery.Helpers; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Navigation; using Microsoft.Windows.AppLifecycle; -using Windows.ApplicationModel.Activation; -using WASDK = Microsoft.WindowsAppSDK; using Microsoft.Windows.AppNotifications; using Microsoft.Windows.AppNotifications.Builder; -using System.Collections.Generic; -using static WinUIGallery.Helpers.Win32; +using Windows.ApplicationModel.Activation; +using WinUIGallery.Helpers; using WinUIGallery.Pages; +using static WinUIGallery.Helpers.Win32; namespace WinUIGallery; @@ -37,34 +33,6 @@ sealed partial class App : Application private static int registeredKeyPressedHook = 0; private HookProc keyEventHook; - - public static string WinAppSdkDetails - { - // TODO: restore patch number and version tag when WinAppSDK supports them both - get => string.Format("Windows App SDK {0}.{1}", - WASDK.Release.Major, WASDK.Release.Minor); - } - - public static string WinAppSdkRuntimeDetails - { - get - { - try - { - // Retrieve Windows App Runtime version info dynamically - IEnumerable windowsAppRuntimeVersion = - from module in Process.GetCurrentProcess().Modules.OfType() - where module.FileName.EndsWith("Microsoft.WindowsAppRuntime.Insights.Resource.dll") - select FileVersionInfo.GetVersionInfo(module.FileName); - return WinAppSdkDetails + ", Windows App Runtime " + windowsAppRuntimeVersion.First().FileVersion; - } - catch - { - return WinAppSdkDetails + $", Windows App Runtime {WASDK.Runtime.Version.Major}.{WASDK.Runtime.Version.Minor}"; - } - } - } - /// /// Get the initial window created for this app. /// @@ -83,22 +51,6 @@ public App() UnhandledException += HandleExceptions; } - /// - /// Converts a string into a enum. - /// - /// The output enum type. - /// The input text. - /// The parsed enum. - /// Thrown when the TEnum type is not a enum. - public static TEnum GetEnum(string text) where TEnum : struct - { - if (!typeof(TEnum).GetTypeInfo().IsEnum) - { - throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum."); - } - return (TEnum)Enum.Parse(typeof(TEnum), text); - } - /// /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. diff --git a/WinUIGallery/Helpers/EnumHelper.cs b/WinUIGallery/Helpers/EnumHelper.cs new file mode 100644 index 000000000..d12d8b4cb --- /dev/null +++ b/WinUIGallery/Helpers/EnumHelper.cs @@ -0,0 +1,22 @@ +using System; +using System.Reflection; + +namespace WinUIGallery.Helpers; +internal static class EnumHelper +{ + /// + /// Converts a string into a enum. + /// + /// The output enum type. + /// The input text. + /// The parsed enum. + /// Thrown when the TEnum type is not a enum. + public static TEnum GetEnum(string text) where TEnum : struct + { + if (!typeof(TEnum).GetTypeInfo().IsEnum) + { + throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum."); + } + return (TEnum)Enum.Parse(typeof(TEnum), text); + } +} diff --git a/WinUIGallery/Helpers/ThemeHelper.cs b/WinUIGallery/Helpers/ThemeHelper.cs index a80d91265..d160ce80b 100644 --- a/WinUIGallery/Helpers/ThemeHelper.cs +++ b/WinUIGallery/Helpers/ThemeHelper.cs @@ -29,7 +29,7 @@ public static ElementTheme ActualTheme } } - return WinUIGallery.App.GetEnum(App.Current.RequestedTheme.ToString()); + return EnumHelper.GetEnum(App.Current.RequestedTheme.ToString()); } } @@ -75,7 +75,7 @@ public static void Initialize() if (savedTheme != null) { - RootTheme = WinUIGallery.App.GetEnum(savedTheme); + RootTheme = EnumHelper.GetEnum(savedTheme); } } } diff --git a/WinUIGallery/Helpers/VersionHelper.cs b/WinUIGallery/Helpers/VersionHelper.cs new file mode 100644 index 000000000..23e7bc3cc --- /dev/null +++ b/WinUIGallery/Helpers/VersionHelper.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using WASDK = Microsoft.WindowsAppSDK; + +namespace WinUIGallery.Helpers; +internal static class VersionHelper +{ + public static string WinAppSdkDetails + { + // TODO: restore patch number and version tag when WinAppSDK supports them both + get => string.Format("Windows App SDK {0}.{1}", + WASDK.Release.Major, WASDK.Release.Minor); + } + + public static string WinAppSdkRuntimeDetails + { + get + { + try + { + // Retrieve Windows App Runtime version info dynamically + IEnumerable windowsAppRuntimeVersion = + from module in Process.GetCurrentProcess().Modules.OfType() + where module.FileName.EndsWith("Microsoft.WindowsAppRuntime.Insights.Resource.dll") + select FileVersionInfo.GetVersionInfo(module.FileName); + return WinAppSdkDetails + ", Windows App Runtime " + windowsAppRuntimeVersion.First().FileVersion; + } + catch + { + return WinAppSdkDetails + $", Windows App Runtime {WASDK.Runtime.Version.Major}.{WASDK.Runtime.Version.Minor}"; + } + } + } +} diff --git a/WinUIGallery/Pages/HomePage.xaml.cs b/WinUIGallery/Pages/HomePage.xaml.cs index dab0088c0..1cfb66d83 100644 --- a/WinUIGallery/Pages/HomePage.xaml.cs +++ b/WinUIGallery/Pages/HomePage.xaml.cs @@ -22,7 +22,7 @@ public HomePage() this.InitializeComponent(); } - public string WinAppSdkDetails => App.WinAppSdkDetails; + public string WinAppSdkDetails => VersionHelper.WinAppSdkDetails; protected override void OnNavigatedTo(NavigationEventArgs e) { diff --git a/WinUIGallery/Pages/SettingsPage.xaml.cs b/WinUIGallery/Pages/SettingsPage.xaml.cs index 30c451f73..f360140c3 100644 --- a/WinUIGallery/Pages/SettingsPage.xaml.cs +++ b/WinUIGallery/Pages/SettingsPage.xaml.cs @@ -32,7 +32,7 @@ public string Version } } - public string WinAppSdkRuntimeDetails => App.WinAppSdkRuntimeDetails; + public string WinAppSdkRuntimeDetails => VersionHelper.WinAppSdkRuntimeDetails; private int lastNavigationSelectionMode = 0; public SettingsPage() @@ -89,7 +89,7 @@ private void themeMode_SelectionChanged(object sender, RoutedEventArgs e) string color; if (selectedTheme != null) { - ThemeHelper.RootTheme = App.GetEnum(selectedTheme); + ThemeHelper.RootTheme = EnumHelper.GetEnum(selectedTheme); if (selectedTheme == "Dark") { TitleBarHelper.SetCaptionButtonColors(window, Colors.White); diff --git a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs index 7ad079bbb..faf0ef842 100644 --- a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs +++ b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs @@ -206,7 +206,7 @@ private void TitleBarHeightComboBox_SelectionChanged(object sender, SelectionCha if (selectedHeight != null && window != null && window.ExtendsContentIntoTitleBar) { - window.AppWindow.TitleBar.PreferredHeightOption = App.GetEnum(selectedHeight); + window.AppWindow.TitleBar.PreferredHeightOption = EnumHelper.GetEnum(selectedHeight); } } From 08b7d45e50072d323cf22b65a7dca7e3d0dc8546 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Fri, 7 Mar 2025 15:12:48 +0100 Subject: [PATCH 2/4] Update NugetPackages --- WinUIGallery/WinUIGallery.csproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index 13a560571..9800b8444 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -119,16 +119,16 @@ - + - - - - - - + + + + + + - + From eab8fcc33b1f23e08ab21324436735056c8e471e Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Fri, 7 Mar 2025 15:25:35 +0100 Subject: [PATCH 3/4] Update WinUIGallery/Helpers/EnumHelper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- WinUIGallery/Helpers/EnumHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinUIGallery/Helpers/EnumHelper.cs b/WinUIGallery/Helpers/EnumHelper.cs index d12d8b4cb..50118e08d 100644 --- a/WinUIGallery/Helpers/EnumHelper.cs +++ b/WinUIGallery/Helpers/EnumHelper.cs @@ -5,7 +5,7 @@ namespace WinUIGallery.Helpers; internal static class EnumHelper { /// - /// Converts a string into a enum. + /// Converts a string into an enum. /// /// The output enum type. /// The input text. From 2fad4ba23ead20e229ee9c52c7b4f7ab56a3428f Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Mon, 10 Mar 2025 16:33:47 +0100 Subject: [PATCH 4/4] Updating packages in standalone.props --- WinUIGallery/WinUIGallery.csproj | 18 +++++++++--------- standalone.props | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index 12bcae7cb..43354ec22 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -119,18 +119,18 @@ - + - - - - - - + + + + + + - + - + diff --git a/standalone.props b/standalone.props index 8738d66f4..b474de756 100644 --- a/standalone.props +++ b/standalone.props @@ -2,12 +2,12 @@ 10.0.22621.42 - 1.6.250108002 + 1.6.250205002 6.2.11 - 1.0.4 - 2.0.13 - 8.0.230907 - 2.0.3 + 1.3.2 + 2.0.15 + 8.1.240916 + 2.2.0 obj\$(MSBuildProjectName)\ bin\$(MSBuildProjectName)\