2025-02-10 20:53:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System.Windows.Markup;
|
|
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
using WPFluent.Appearance;
|
|
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
namespace WPFluent.Markup;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-05-05 17:04:06 +08:00
|
|
|
|
/// 提供一个字典实现,其中包含组件和其他设备使用的 <c>WPF UI</c> 主题资源。
|
2025-02-10 20:53:40 +08:00
|
|
|
|
/// elements of a WPF application.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <example>
|
2025-05-05 17:04:06 +08:00
|
|
|
|
/// <code lang="xml">
|
|
|
|
|
|
/// <Application
|
|
|
|
|
|
/// xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
|
|
|
|
|
|
/// <Application.Resources>
|
|
|
|
|
|
/// <ResourceDictionary>
|
|
|
|
|
|
/// <ResourceDictionary.MergedDictionaries>
|
|
|
|
|
|
/// <ui:ThemesDictionary Theme = "Dark" />
|
|
|
|
|
|
/// </ResourceDictionary.MergedDictionaries>
|
|
|
|
|
|
/// </ResourceDictionary>
|
|
|
|
|
|
/// </Application.Resources>
|
|
|
|
|
|
/// </Application>
|
|
|
|
|
|
/// </code>
|
2025-02-10 20:53:40 +08:00
|
|
|
|
/// </example>
|
|
|
|
|
|
[Localizability(LocalizationCategory.Ignore)]
|
|
|
|
|
|
[Ambient]
|
|
|
|
|
|
[UsableDuringInitialization(true)]
|
|
|
|
|
|
public class ThemesDictionary : ResourceDictionary
|
|
|
|
|
|
{
|
2025-05-05 17:04:06 +08:00
|
|
|
|
public ThemesDictionary() { SetSourceBasedOnSelectedTheme(ThemeType.Light); }
|
2025-02-10 20:53:40 +08:00
|
|
|
|
|
2025-05-05 17:04:06 +08:00
|
|
|
|
private void SetSourceBasedOnSelectedTheme(ThemeType? selectedApplicationTheme)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
var themeName = selectedApplicationTheme switch
|
|
|
|
|
|
{
|
2025-05-05 17:04:06 +08:00
|
|
|
|
ThemeType.Light => "Light",
|
|
|
|
|
|
ThemeType.Dark => "Dark",
|
|
|
|
|
|
ThemeType.HcWhite => "HCWhite",
|
|
|
|
|
|
ThemeType.HcBlack => "HCBlack",
|
2025-02-10 20:53:40 +08:00
|
|
|
|
_ => "Light",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-05 17:04:06 +08:00
|
|
|
|
Source = new Uri($"{ThemeManager.ThemesDictionaryPath}{themeName}.xaml", UriKind.Absolute);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the default application theme.
|
|
|
|
|
|
/// </summary>
|
2025-05-05 17:04:06 +08:00
|
|
|
|
public ThemeType Theme { set => SetSourceBasedOnSelectedTheme(value); }
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|