月更
This commit is contained in:
32
AntDesignWPF/Appearance/ThemesDictionary.cs
Normal file
32
AntDesignWPF/Appearance/ThemesDictionary.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Windows.Markup;
|
||||
|
||||
|
||||
namespace AntDesignWPF.Appearance;
|
||||
|
||||
/// <summary>
|
||||
/// 提供一个字典实现,其中包含组件和其他设备使用的主题资源。
|
||||
/// </summary>
|
||||
[Localizability(LocalizationCategory.Ignore)]
|
||||
[Ambient]
|
||||
[UsableDuringInitialization(true)]
|
||||
public class ThemesDictionary : ResourceDictionary
|
||||
{
|
||||
public ThemesDictionary() { SetSourceBasedOnSelectedTheme(ThemeMode.Light); }
|
||||
|
||||
private void SetSourceBasedOnSelectedTheme(ThemeMode? selectedApplicationTheme)
|
||||
{
|
||||
var themeName = selectedApplicationTheme switch
|
||||
{
|
||||
ThemeMode.Light => "Light",
|
||||
ThemeMode.Dark => "Dark",
|
||||
_ => "Light",
|
||||
};
|
||||
|
||||
Source = new Uri($"{ThemeManager.ThemesDictionaryPath}{themeName}.xaml", UriKind.Absolute);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认应用程序主题。
|
||||
/// </summary>
|
||||
public ThemeMode Theme { set => SetSourceBasedOnSelectedTheme(value); }
|
||||
}
|
||||
Reference in New Issue
Block a user