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 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 modificationAction) { var paletteHelper = new PaletteHelper(); ITheme theme = paletteHelper.GetTheme(); modificationAction?.Invoke(theme); paletteHelper.SetTheme(theme); } private readonly PaletteHelper paletteHelper = new PaletteHelper(); /// /// 改变颜色 /// /// [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; } } }