JT
2 years ago
committed by
GitHub
8 changed files with 156 additions and 4 deletions
@ -0,0 +1,30 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Page |
||||||
|
x:Class="StabilityMatrix.SettingsPage" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:local="using:StabilityMatrix" |
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||||
|
xmlns:viewModels="using:StabilityMatrix.ViewModels" |
||||||
|
xmlns:models="using:StabilityMatrix.Models" |
||||||
|
xmlns:labs="using:CommunityToolkit.Labs.WinUI" |
||||||
|
mc:Ignorable="d" |
||||||
|
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> |
||||||
|
|
||||||
|
<Page.DataContext> |
||||||
|
<viewModels:SettingsViewModel/> |
||||||
|
</Page.DataContext> |
||||||
|
|
||||||
|
<ScrollViewer Margin="20"> |
||||||
|
<StackPanel Spacing="3"> |
||||||
|
<labs:SettingsCard x:Name="SettingsCard" |
||||||
|
Header="Choose UI Theme"> |
||||||
|
<ComboBox |
||||||
|
ItemsSource="{Binding AvailableThemes}" |
||||||
|
SelectedItem="{Binding SelectedTheme, Mode=TwoWay}" |
||||||
|
Header="Theme" Width="200"/> |
||||||
|
</labs:SettingsCard> |
||||||
|
</StackPanel> |
||||||
|
</ScrollViewer> |
||||||
|
</Page> |
@ -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 |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// An empty page that can be used on its own or navigated to within a Frame. |
||||||
|
/// </summary> |
||||||
|
public sealed partial class SettingsPage : Page |
||||||
|
{ |
||||||
|
public SettingsPage() |
||||||
|
{ |
||||||
|
this.InitializeComponent(); |
||||||
|
DataContext = new SettingsViewModel(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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<string> 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)); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue