Compare commits

...

4 Commits

Author SHA1 Message Date
Bugadinho
a5d4b1e85f
Merge f23d2bce88 into 552f2a52a6 2025-03-02 14:49:43 +01:00
Bugadinho
f23d2bce88
Set WindowBackdropType to allow for dynamic theme change 2025-01-06 21:43:46 -03:00
Bugadinho
e983814176
ColorValuesChanged now reapplies the theme 2025-01-06 21:43:41 -03:00
Bugadinho
4795bf8b66
Use WinRT to get dark theme 2025-01-06 21:43:31 -03:00
11 changed files with 26 additions and 5 deletions

View File

@ -1,4 +1,4 @@
using Microsoft.Win32;
using Windows.UI.ViewManagement;
namespace Bloxstrap.Extensions
{
@ -9,9 +9,9 @@ namespace Bloxstrap.Extensions
if (dialogTheme != Theme.Default)
return dialogTheme;
using var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
if (key?.GetValue("AppsUseLightTheme") is int value && value == 0)
var settings = new UISettings();
var background = settings.GetColorValue(UIColorType.Background);
if (((5 * background.G) + (2 * background.R) + background.B) < (8 * 128))
return Theme.Dark;
return Theme.Light;

View File

@ -4,23 +4,27 @@ using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services;
using Windows.UI.ViewManagement;
namespace Bloxstrap.UI.Elements.Base
{
public abstract class WpfUiWindow : UiWindow
{
private readonly IThemeService _themeService = new ThemeService();
private UISettings _settings;
public WpfUiWindow()
{
ApplyTheme();
_settings = new UISettings();
_settings.ColorValuesChanged += ColorValuesChanged;
}
public void ApplyTheme()
{
_themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light);
_themeService.SetSystemAccent();
#if QA_BUILD
this.BorderBrush = System.Windows.Media.Brushes.Red;
this.BorderThickness = new Thickness(4);
@ -37,5 +41,13 @@ namespace Bloxstrap.UI.Elements.Base
base.OnSourceInitialized(e);
}
private async void ColorValuesChanged(UISettings sender, object args)
{
await Dispatcher.InvokeAsync(() =>
{
ApplyTheme();
});
}
}
}

View File

@ -18,6 +18,7 @@
Height="420"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>

View File

@ -18,6 +18,7 @@
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>

View File

@ -16,6 +16,7 @@
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<ui:UiWindow.Resources>
<converters:RangeConverter x:Key="ValidationConverter" From="0" />

View File

@ -15,6 +15,7 @@
Title="{x:Static resources:Strings.Dialog_Connectivity_Title}"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>

View File

@ -16,6 +16,7 @@
SizeToContent="Height"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>

View File

@ -18,6 +18,7 @@
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>

View File

@ -16,6 +16,7 @@
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>

View File

@ -17,6 +17,7 @@
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>

View File

@ -19,6 +19,7 @@
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>