From 34741099ec1d27bb84ae4b48bfc2a07bec1afcc8 Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 24 May 2023 16:52:48 -0400 Subject: [PATCH 1/5] Create WindowOptions.cs --- StabilityMatrix/WindowOptions.cs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 StabilityMatrix/WindowOptions.cs diff --git a/StabilityMatrix/WindowOptions.cs b/StabilityMatrix/WindowOptions.cs new file mode 100644 index 00000000..665aea8b --- /dev/null +++ b/StabilityMatrix/WindowOptions.cs @@ -0,0 +1,34 @@ +using Microsoft.UI; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using WinRT.Interop; + +namespace StabilityMatrix; + +public static class WindowOptions +{ + public static void TrySetCustomTitle(Window window, UIElement titleBar) + { + // Use custom title bar if supported + if (AppWindowTitleBar.IsCustomizationSupported()) + { + var appWindow = GetAppWindow(window); + // Hide default title bar + appWindow.TitleBar.ExtendsContentIntoTitleBar = true; + // Set new title bar + window.SetTitleBar(titleBar); + } + else + { + // Customization is not supported, hide the custom title bar + titleBar.Visibility = Visibility.Collapsed; + } + } + + private static AppWindow GetAppWindow(Window window) + { + var hWnd = WindowNative.GetWindowHandle(window); + var wndId = Win32Interop.GetWindowIdFromWindow(hWnd); + return AppWindow.GetFromWindowId(wndId); + } +} \ No newline at end of file From a1fcd71d1630e2f8ba3f65322a56eb6a0c8ea18d Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 24 May 2023 16:53:58 -0400 Subject: [PATCH 2/5] Add custom title and icons for nav menu --- StabilityMatrix/MainWindow.xaml | 54 ++++++++++++++++++++++++------ StabilityMatrix/MainWindow.xaml.cs | 12 +++++-- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/StabilityMatrix/MainWindow.xaml b/StabilityMatrix/MainWindow.xaml index 39ce9e5d..2353e407 100644 --- a/StabilityMatrix/MainWindow.xaml +++ b/StabilityMatrix/MainWindow.xaml @@ -7,17 +7,49 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> - + + + + + + + + + + + + - - - - + + + + + + - - + + + + + + + + + + + + \ No newline at end of file diff --git a/StabilityMatrix/MainWindow.xaml.cs b/StabilityMatrix/MainWindow.xaml.cs index f332842f..c41ca420 100644 --- a/StabilityMatrix/MainWindow.xaml.cs +++ b/StabilityMatrix/MainWindow.xaml.cs @@ -2,6 +2,11 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System; using System.Linq; +using Windows.ApplicationModel.Core; +using Windows.UI.ViewManagement; +using Microsoft.UI; +using Microsoft.UI.Windowing; +using WinRT.Interop; namespace StabilityMatrix { @@ -12,10 +17,11 @@ namespace StabilityMatrix { public MainWindow() { - this.InitializeComponent(); + InitializeComponent(); + Title = "Stability Matrix"; + WindowOptions.TrySetCustomTitle(this, AppTitleBar); } - - + private void ButtonNavInstallPage_OnClick(object sender, RoutedEventArgs e) { ContentFrame.Navigate(typeof(InstallPage)); From 9071c3c2819c68826e3afc1b086d046900fa2492 Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 24 May 2023 16:54:18 -0400 Subject: [PATCH 3/5] Add static resource AppTitle --- StabilityMatrix/App.xaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/StabilityMatrix/App.xaml b/StabilityMatrix/App.xaml index 78057bc6..3f4c4460 100644 --- a/StabilityMatrix/App.xaml +++ b/StabilityMatrix/App.xaml @@ -1,6 +1,3 @@ - - - + Stability Matrix From b92fe6329802882324a638fff651ac67f491334d Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 24 May 2023 17:15:08 -0400 Subject: [PATCH 4/5] Add SettingsPage and SettingsViewModel --- StabilityMatrix/SettingsPage.xaml | 30 ++++++++++ StabilityMatrix/SettingsPage.xaml.cs | 33 +++++++++++ StabilityMatrix/StabilityMatrix.csproj | 8 +++ .../ViewModels/SettingsViewModel.cs | 55 +++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 StabilityMatrix/SettingsPage.xaml create mode 100644 StabilityMatrix/SettingsPage.xaml.cs create mode 100644 StabilityMatrix/ViewModels/SettingsViewModel.cs diff --git a/StabilityMatrix/SettingsPage.xaml b/StabilityMatrix/SettingsPage.xaml new file mode 100644 index 00000000..6b7b0fb6 --- /dev/null +++ b/StabilityMatrix/SettingsPage.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + diff --git a/StabilityMatrix/SettingsPage.xaml.cs b/StabilityMatrix/SettingsPage.xaml.cs new file mode 100644 index 00000000..7ad8ad2b --- /dev/null +++ b/StabilityMatrix/SettingsPage.xaml.cs @@ -0,0 +1,33 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using StabilityMatrix.ViewModels; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace StabilityMatrix +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class SettingsPage : Page + { + public SettingsPage() + { + this.InitializeComponent(); + DataContext = new SettingsViewModel(); + } + } +} diff --git a/StabilityMatrix/StabilityMatrix.csproj b/StabilityMatrix/StabilityMatrix.csproj index 08d0364b..44b92ada 100644 --- a/StabilityMatrix/StabilityMatrix.csproj +++ b/StabilityMatrix/StabilityMatrix.csproj @@ -18,6 +18,7 @@ + @@ -31,6 +32,7 @@ + @@ -58,6 +60,12 @@ + + + MSBuild:Compile + + + MSBuild:Compile diff --git a/StabilityMatrix/ViewModels/SettingsViewModel.cs b/StabilityMatrix/ViewModels/SettingsViewModel.cs new file mode 100644 index 00000000..31f6812a --- /dev/null +++ b/StabilityMatrix/ViewModels/SettingsViewModel.cs @@ -0,0 +1,55 @@ +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using CommunityToolkit.Mvvm.Input; +using Microsoft.UI.Xaml; +using StabilityMatrix.Helper; +using StabilityMatrix.Models; + +namespace StabilityMatrix.ViewModels; + +internal class SettingsViewModel : INotifyPropertyChanged +{ + public ObservableCollection AvailableThemes => new() + { + "Light", + "Dark", + "System", + }; + private string selectedTheme; + + public string SelectedTheme + { + get => selectedTheme; + set + { + if (value == selectedTheme) return; + selectedTheme = value; + OnPropertyChanged(); + + // Update theme + switch (selectedTheme) + { + case "Light": + Application.Current.RequestedTheme = ApplicationTheme.Light; + break; + case "Dark": + Application.Current.RequestedTheme = ApplicationTheme.Dark; + break; + } + } + } + + public SettingsViewModel() + { + SelectedTheme = "System"; + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} \ No newline at end of file From b6e7573e0d7947691e2717b2e1f2799aad5867fa Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 24 May 2023 17:15:22 -0400 Subject: [PATCH 5/5] Add SettingsPage to navigation --- StabilityMatrix/MainWindow.xaml.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/StabilityMatrix/MainWindow.xaml.cs b/StabilityMatrix/MainWindow.xaml.cs index c41ca420..5c06268a 100644 --- a/StabilityMatrix/MainWindow.xaml.cs +++ b/StabilityMatrix/MainWindow.xaml.cs @@ -56,6 +56,9 @@ namespace StabilityMatrix case "LaunchPage": ContentFrame.Navigate(typeof(LaunchPage)); break; + case "Settings": + ContentFrame.Navigate(typeof(SettingsPage)); + break; default: throw new ArgumentException($"Invalid tag: {tag}"); }