Browse Source

Merge branch 'main' into ui-updates

pull/5/head
JT 2 years ago committed by GitHub
parent
commit
4063ab6026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      StabilityMatrix/App.xaml
  2. 2
      StabilityMatrix/MainWindow.xaml
  3. 2
      StabilityMatrix/MainWindow.xaml.cs
  4. 30
      StabilityMatrix/SettingsPage.xaml
  5. 33
      StabilityMatrix/SettingsPage.xaml.cs
  6. 2
      StabilityMatrix/StabilityMatrix.csproj
  7. 55
      StabilityMatrix/ViewModels/SettingsViewModel.cs
  8. 34
      StabilityMatrix/WindowOptions.cs

2
StabilityMatrix/App.xaml

@ -1,4 +1,4 @@
<Application x:Class="StabilityMatrix.App"
<Application x:Class="StabilityMatrix.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StabilityMatrix"

2
StabilityMatrix/MainWindow.xaml

@ -1,4 +1,4 @@
<ui:FluentWindow x:Class="StabilityMatrix.MainWindow"
<ui:FluentWindow x:Class="StabilityMatrix.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

2
StabilityMatrix/MainWindow.xaml.cs

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

30
StabilityMatrix/SettingsPage.xaml

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

33
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
{
/// <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();
}
}
}

2
StabilityMatrix/StabilityMatrix.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>

55
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<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));
}
}

34
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);
}
}
Loading…
Cancel
Save