using System.Windows.Markup; using WPFluent.Appearance; namespace WPFluent.Markup; /// /// 提供一个字典实现,其中包含组件和其他设备使用的 WPF UI 主题资源。 /// elements of a WPF application. /// /// /// /// <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> /// /// [Localizability(LocalizationCategory.Ignore)] [Ambient] [UsableDuringInitialization(true)] public class ThemesDictionary : ResourceDictionary { public ThemesDictionary() { SetSourceBasedOnSelectedTheme(ThemeType.Light); } private void SetSourceBasedOnSelectedTheme(ThemeType? selectedApplicationTheme) { var themeName = selectedApplicationTheme switch { ThemeType.Light => "Light", ThemeType.Dark => "Dark", ThemeType.HcWhite => "HCWhite", ThemeType.HcBlack => "HCBlack", _ => "Light", }; Source = new Uri($"{ThemeManager.ThemesDictionaryPath}{themeName}.xaml", UriKind.Absolute); } /// /// Sets the default application theme. /// public ThemeType Theme { set => SetSourceBasedOnSelectedTheme(value); } }