添加项目文件。
This commit is contained in:
77
WPFWCSDemo/ViewModels/Settings/SkinViewModel.cs
Normal file
77
WPFWCSDemo/ViewModels/Settings/SkinViewModel.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using MaterialDesignColors;
|
||||
using MaterialDesignColors.ColorManipulation;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace WPFWCSDemo.ViewModels.Settings
|
||||
{
|
||||
public partial class SkinViewModel:ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
static Frame frame;
|
||||
|
||||
public IEnumerable<ISwatch> Swatches { get; } = SwatchHelper.Swatches;
|
||||
|
||||
|
||||
//深浅色切换
|
||||
private bool _isDarkTheme;
|
||||
public bool IsDarkTheme
|
||||
{
|
||||
get => _isDarkTheme;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _isDarkTheme, value))
|
||||
{
|
||||
ModifyTheme(theme => theme.SetBaseTheme(value ? Theme.Dark : Theme.Light));
|
||||
}
|
||||
}
|
||||
}
|
||||
//切换主题
|
||||
private static void ModifyTheme(Action<ITheme> modificationAction)
|
||||
{
|
||||
var paletteHelper = new PaletteHelper();
|
||||
ITheme theme = paletteHelper.GetTheme();
|
||||
|
||||
modificationAction?.Invoke(theme);
|
||||
|
||||
paletteHelper.SetTheme(theme);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private readonly PaletteHelper paletteHelper = new PaletteHelper();
|
||||
|
||||
/// <summary>
|
||||
/// 改变颜色
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
[RelayCommand]
|
||||
public void ChangeHue(object? obj)
|
||||
{
|
||||
var hue = (Color)obj!;
|
||||
|
||||
ITheme theme = paletteHelper.GetTheme();
|
||||
|
||||
theme.PrimaryLight = new ColorPair(hue.Lighten());
|
||||
theme.PrimaryMid = new ColorPair(hue);
|
||||
theme.PrimaryDark = new ColorPair(hue.Darken());
|
||||
|
||||
paletteHelper.SetTheme(theme);
|
||||
}
|
||||
|
||||
|
||||
public static void GetFrame(Frame navigationFrame)
|
||||
{
|
||||
frame = navigationFrame;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user