添加项目文件。
This commit is contained in:
60
MetroGauges/ViewModel/PaletteSelectorViewModel.cs
Normal file
60
MetroGauges/ViewModel/PaletteSelectorViewModel.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using MaterialDesignColors;
|
||||
|
||||
namespace MetroGauges.Controls
|
||||
{
|
||||
public class PaletteSelectorViewModel
|
||||
{
|
||||
public PaletteSelectorViewModel()
|
||||
{
|
||||
Swatches = new SwatchesProvider().Swatches;
|
||||
}
|
||||
|
||||
public ICommand ToggleBaseCommand { get; } = new AnotherCommandImplementation(o => ApplyBase((bool)o));
|
||||
|
||||
public IEnumerable<Swatch> Swatches { get; }
|
||||
|
||||
public ICommand ApplyPrimaryCommand { get; } = new AnotherCommandImplementation(o => ApplyPrimary((Swatch)o));
|
||||
|
||||
public ICommand ApplyAccentCommand { get; } = new AnotherCommandImplementation(o => ApplyAccent((Swatch)o));
|
||||
|
||||
private static void ApplyBase(bool isDark)
|
||||
{
|
||||
new PaletteHelper().SetLightDark(isDark);
|
||||
|
||||
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
if (isDark)
|
||||
{
|
||||
cfa.AppSettings.Settings["Intensity"].Value = "Dark";
|
||||
}
|
||||
else
|
||||
{
|
||||
cfa.AppSettings.Settings["Intensity"].Value = "Light";
|
||||
}
|
||||
cfa.Save();
|
||||
}
|
||||
|
||||
private static void ApplyPrimary(Swatch swatch)
|
||||
{
|
||||
new PaletteHelper().ReplacePrimaryColor(swatch);
|
||||
|
||||
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
cfa.AppSettings.Settings["Primary"].Value = swatch.Name;
|
||||
cfa.Save();
|
||||
}
|
||||
|
||||
private static void ApplyAccent(Swatch swatch)
|
||||
{
|
||||
new PaletteHelper().ReplaceAccentColor(swatch);
|
||||
|
||||
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
cfa.AppSettings.Settings["Accent"].Value = swatch.Name;
|
||||
cfa.Save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user