feat: add ThemeHelper

This commit is contained in:
枫雨
2023-04-07 18:12:54 +08:00
parent 3dfe76e893
commit e2fd405dcb
7 changed files with 55 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
xmlns:s="https://github.com/canton7/Stylet"
xmlns:main="clr-namespace:MaaWpfGui.Main"
xmlns:styles="clr-namespace:MaaWpfGui.Styles"
xmlns:resources="clr-namespace:MaaWpfGui.Helper"
xmlns:controls="clr-namespace:MaaWpfGui.Styles.Controls"
xmlns:hc="https://handyorg.github.io/handycontrol">
<Application.Resources>
@@ -28,6 +29,7 @@
</s:ApplicationLoader.Bootstrapper>
</s:ApplicationLoader>
<hc:Theme Name="HandyTheme"/>
<resources:ThemeHelper Name="MaaTheme"/>
</ResourceDictionary.MergedDictionaries>
<!-- A Style that affects all TextBlocks -->
<Style BasedOn="{StaticResource TextBlockDefault}" TargetType="controls:TextBlock" />

View File

@@ -42,6 +42,7 @@ namespace MaaWpfGui
{
SharedResourceDictionary.SharedDictionaries.Clear();
Theme.GetTheme("HandyTheme", Resources).Skin = skin;
Theme.GetTheme("MaaTheme", Resources).Skin = skin;
Current.MainWindow?.OnApplyTemplate();
}
@@ -49,6 +50,7 @@ namespace MaaWpfGui
{
SharedResourceDictionary.SharedDictionaries.Clear();
Theme.GetTheme("HandyTheme", Resources).SyncWithSystem = syncWithSystem;
Theme.GetTheme("MaaTheme", Resources).SyncWithSystem = syncWithSystem;
Current.MainWindow?.OnApplyTemplate();
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Windows;
using HandyControl.Data;
using HandyControl.Themes;
using HandyControl.Tools;
namespace MaaWpfGui.Helper
{
/// <summary>
/// The theme class.
/// </summary>
public class ThemeHelper : Theme
{
public override ResourceDictionary GetSkin(SkinType skinType) =>
ResourceHelper.GetSkin(typeof(App).Assembly, "Res/Themes", skinType);
public override ResourceDictionary GetTheme() => new ResourceDictionary()
{
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml"),
};
}
}

View File

@@ -0,0 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<Color x:Key="SecondaryRegionColor">#ffffff</Color>
</ResourceDictionary>

View File

@@ -0,0 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<Color x:Key="PrimaryTextColor">#ddd</Color>
<Color x:Key="TextIconColor">#ddd</Color>
</ResourceDictionary>

View File

@@ -0,0 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ColorsDark.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

View File

@@ -0,0 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>