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..50118e08d --- /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 an 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 52492b70e..a81772f8e 100644 --- a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs +++ b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs @@ -203,7 +203,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); } } diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index b0eec4242..769e9d82c 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -131,7 +131,7 @@ - + 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)\