mirror of
https://github.com/holgerb83/ModernWpfPlayground.git
synced 2025-04-19 23:03:49 +02:00
refactoring enums
This commit is contained in:
parent
94f5eced01
commit
b1e70f09b1
@ -1,10 +0,0 @@
|
|||||||
namespace ModernWpfPlayground
|
|
||||||
{
|
|
||||||
public enum AccentColor
|
|
||||||
{
|
|
||||||
Green,
|
|
||||||
Yellow,
|
|
||||||
Blue,
|
|
||||||
Purple
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
|
||||||
using ModernWpf;
|
using ModernWpf;
|
||||||
|
using ModernWpfPlayground.Types;
|
||||||
using Prism.Ioc;
|
using Prism.Ioc;
|
||||||
|
|
||||||
namespace ModernWpfPlayground
|
namespace ModernWpfPlayground
|
||||||
@ -13,10 +13,11 @@ namespace ModernWpfPlayground
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
ThemeManager.Current.AccentColor = Color.FromArgb(255, 0, 86, 76);
|
|
||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
|
ThemeManager.Current.AccentColor = AccentColors.Green.ToWindowsColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||||
{
|
{
|
||||||
containerRegistry.Register<MainWindow>();
|
containerRegistry.Register<MainWindow>();
|
||||||
|
@ -246,7 +246,7 @@
|
|||||||
|
|
||||||
<ui:SimpleStackPanel Margin="5" Spacing="10">
|
<ui:SimpleStackPanel Margin="5" Spacing="10">
|
||||||
<controls:PropertyPresenter Label="Theme Mode" Value="{Binding ThemeMode}" />
|
<controls:PropertyPresenter Label="Theme Mode" Value="{Binding ThemeMode}" />
|
||||||
<controls:PropertyPresenter Label="Accent color" Value="{Binding AccentColor}" />
|
<controls:PropertyPresenter Label="Accent color" Value="{Binding AccentColors}" />
|
||||||
<controls:PropertyPresenter
|
<controls:PropertyPresenter
|
||||||
Command="{Binding ShowDialogCommand}"
|
Command="{Binding ShowDialogCommand}"
|
||||||
Label="Hello"
|
Label="Hello"
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using ModernWpf;
|
|
||||||
using ModernWpfPlayground.MvvmStuff;
|
using ModernWpfPlayground.MvvmStuff;
|
||||||
|
using ModernWpfPlayground.Types;
|
||||||
using Prism.Commands;
|
using Prism.Commands;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
|
using static ModernWpf.ThemeManager;
|
||||||
|
|
||||||
namespace ModernWpfPlayground
|
namespace ModernWpfPlayground
|
||||||
{
|
{
|
||||||
@ -96,23 +95,13 @@ namespace ModernWpfPlayground
|
|||||||
set => SetProperty(value, SetTheme);
|
set => SetProperty(value, SetTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccentColor AccentColor
|
public AccentColors AccentColors
|
||||||
{
|
{
|
||||||
get => GetProperty(AccentColor.Green);
|
get => GetProperty(AccentColors.Green);
|
||||||
set => SetProperty(value, SetAccentColor);
|
set => SetProperty(value, SetAccentColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetAccentColor(AccentColor accentColor)
|
private static void SetAccentColor(AccentColors accentColors) => Current.AccentColor = accentColors.ToWindowsColor();
|
||||||
{
|
|
||||||
ThemeManager.Current.AccentColor = accentColor switch
|
|
||||||
{
|
|
||||||
AccentColor.Green => Color.FromArgb(255, 0, 86, 76),
|
|
||||||
AccentColor.Yellow => Color.FromArgb(255, 164, 144, 0),
|
|
||||||
AccentColor.Blue => Color.FromArgb(255, 0, 120, 215),
|
|
||||||
AccentColor.Purple => Color.FromArgb(255, 104, 33, 122),
|
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(accentColor), accentColor, null)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public int WindowWidth
|
public int WindowWidth
|
||||||
{
|
{
|
||||||
@ -132,16 +121,7 @@ namespace ModernWpfPlayground
|
|||||||
set => SetProperty(value);
|
set => SetProperty(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetTheme(ThemeMode themeMode)
|
private static void SetTheme(ThemeMode themeMode) => Current.ApplicationTheme = themeMode.ToApplicationTheme();
|
||||||
{
|
|
||||||
ThemeManager.Current.ApplicationTheme = themeMode switch
|
|
||||||
{
|
|
||||||
ThemeMode.Light => ApplicationTheme.Light,
|
|
||||||
ThemeMode.Dark => ApplicationTheme.Dark,
|
|
||||||
ThemeMode.UseSystemSetting => default,
|
|
||||||
_ => ThemeManager.Current.ApplicationTheme
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowDialog()
|
private void ShowDialog()
|
||||||
{
|
{
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace ModernWpfPlayground
|
|
||||||
{
|
|
||||||
public enum ThemeMode
|
|
||||||
{
|
|
||||||
[Description("Light")] Light,
|
|
||||||
[Description("Dark")] Dark,
|
|
||||||
[Description("Use system setting")] UseSystemSetting
|
|
||||||
}
|
|
||||||
}
|
|
30
App/Types/AccentColors.cs
Normal file
30
App/Types/AccentColors.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace ModernWpfPlayground.Types
|
||||||
|
{
|
||||||
|
public enum AccentColors
|
||||||
|
{
|
||||||
|
Green,
|
||||||
|
Yellow,
|
||||||
|
Blue,
|
||||||
|
Purple,
|
||||||
|
Red
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AccentColorExtension
|
||||||
|
{
|
||||||
|
public static Color ToWindowsColor(this AccentColors accentColor)
|
||||||
|
{
|
||||||
|
return accentColor switch
|
||||||
|
{
|
||||||
|
AccentColors.Green => Color.FromRgb(0, 86, 76),
|
||||||
|
AccentColors.Yellow => Color.FromRgb(164, 144, 0),
|
||||||
|
AccentColors.Blue => Color.FromRgb(0, 120, 215),
|
||||||
|
AccentColors.Purple => Color.FromRgb(104, 33, 122),
|
||||||
|
AccentColors.Red => Color.FromRgb(183, 71, 42),
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(accentColor), accentColor, null)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
App/Types/ThemeMode.cs
Normal file
27
App/Types/ThemeMode.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using ModernWpf;
|
||||||
|
|
||||||
|
namespace ModernWpfPlayground.Types
|
||||||
|
{
|
||||||
|
public enum ThemeMode
|
||||||
|
{
|
||||||
|
[Description("Light")] Light,
|
||||||
|
[Description("Dark")] Dark,
|
||||||
|
[Description("Use system setting")] UseSystemSetting
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ThemeModeExtension
|
||||||
|
{
|
||||||
|
public static ApplicationTheme? ToApplicationTheme(this ThemeMode themeMode)
|
||||||
|
{
|
||||||
|
return themeMode switch
|
||||||
|
{
|
||||||
|
ThemeMode.Light => ApplicationTheme.Light,
|
||||||
|
ThemeMode.Dark => ApplicationTheme.Dark,
|
||||||
|
ThemeMode.UseSystemSetting => default,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(themeMode), themeMode, null)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user