整理控件库
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
|
||||
|
||||
|
||||
namespace WPFluent.Markup;
|
||||
|
||||
/// <summary>
|
||||
/// Custom design time attributes based on Marcin Najder implementation.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code lang="xml"> /// <ui:FluentWindow /// xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" ///
|
||||
/// ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" /// ui:Design.Foreground="{DynamicResource
|
||||
/// TextFillColorPrimaryBrush}"> /// <Button Content="Hello World" /> /// </FluentWindow> ///</code>
|
||||
/// </example>
|
||||
public static class Design
|
||||
{
|
||||
private static bool? _inDesignMode;
|
||||
private static readonly string[] DesignProcesses =
|
||||
[
|
||||
"devenv",
|
||||
"dotnet",
|
||||
"RiderWpfPreviewerLauncher64"
|
||||
];
|
||||
|
||||
public static readonly DependencyProperty BackgroundProperty = DependencyProperty.RegisterAttached(
|
||||
"Background",
|
||||
typeof(System.Windows.Media.Brush),
|
||||
typeof(Design),
|
||||
new PropertyMetadata(OnBackgroundChanged));
|
||||
|
||||
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.RegisterAttached(
|
||||
"Foreground",
|
||||
typeof(System.Windows.Media.Brush),
|
||||
typeof(Design),
|
||||
new PropertyMetadata(OnForegroundChanged));
|
||||
|
||||
private static void OnBackgroundChanged(DependencyObject? d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if(!InDesignMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
d?.GetType()?.GetProperty("Background")?.SetValue(d, e.NewValue, null);
|
||||
}
|
||||
|
||||
private static void OnForegroundChanged(DependencyObject? d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if(!InDesignMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
d?.GetType()?.GetProperty("Foreground")?.SetValue(d, e.NewValue, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the framework is in design-time mode. (Caliburn.Micro implementation)
|
||||
/// </summary>
|
||||
private static bool InDesignMode => _inDesignMode ??=
|
||||
(bool)
|
||||
DependencyPropertyDescriptor
|
||||
.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement))
|
||||
.Metadata.DefaultValue ||
|
||||
DesignProcesses.Any(
|
||||
process => System
|
||||
.Diagnostics.Process
|
||||
.GetCurrentProcess()
|
||||
.ProcessName
|
||||
.StartsWith(process, StringComparison.Ordinal));
|
||||
|
||||
/// <summary>
|
||||
/// Helper for getting <see cref="BackgroundProperty"/> from <paramref name="dependencyObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="dependencyObject"><see cref="DependencyObject"/> to read <see cref="BackgroundProperty"/> from.</param>
|
||||
/// <returns>Background property value.</returns>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage(
|
||||
"WpfAnalyzers.DependencyProperty",
|
||||
"WPF0033:Add [AttachedPropertyBrowsableForType]",
|
||||
Justification = "Because")]
|
||||
public static System.Windows.Media.Brush? GetBackground(DependencyObject dependencyObject) => (System.Windows.Media.Brush)dependencyObject.GetValue(
|
||||
BackgroundProperty);
|
||||
|
||||
/// <summary>
|
||||
/// Helper for getting <see cref="ForegroundProperty"/> from <paramref name="dependencyObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="dependencyObject"><see cref="DependencyObject"/> to read <see cref="ForegroundProperty"/> from.</param>
|
||||
/// <returns>Foreground property value.</returns>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage(
|
||||
"WpfAnalyzers.DependencyProperty",
|
||||
"WPF0033:Add [AttachedPropertyBrowsableForType]",
|
||||
Justification = "Because")]
|
||||
public static System.Windows.Media.Brush? GetForeground(DependencyObject dependencyObject) => (System.Windows.Media.Brush)dependencyObject.GetValue(
|
||||
ForegroundProperty);
|
||||
|
||||
/// <summary>
|
||||
/// Helper for setting <see cref="BackgroundProperty"/> on <paramref name="dependencyObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="dependencyObject"><see cref="DependencyObject"/> to set <see cref="BackgroundProperty"/> on.</param>
|
||||
/// <param name="value">Background property value.</param>
|
||||
public static void SetBackground(DependencyObject dependencyObject, System.Windows.Media.Brush? value) => dependencyObject.SetValue(
|
||||
BackgroundProperty,
|
||||
value);
|
||||
|
||||
/// <summary>
|
||||
/// Helper for setting <see cref="ForegroundProperty"/> on <paramref name="dependencyObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="dependencyObject"><see cref="DependencyObject"/> to set <see cref="ForegroundProperty"/> on.</param>
|
||||
/// <param name="value">Foreground property value.</param>
|
||||
public static void SetForeground(DependencyObject dependencyObject, System.Windows.Media.Brush? value) => dependencyObject.SetValue(
|
||||
ForegroundProperty,
|
||||
value);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using WPFluent.Controls;
|
||||
namespace WPFluent.Markup;
|
||||
|
||||
/// <summary>
|
||||
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="FontIcon"/>.
|
||||
/// FontIcon <see cref="MarkupExtension"/> which can provide <see cref="FontIcon"/>.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code lang="xml"> /// <ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Windows.Markup;
|
||||
namespace WPFluent.Markup;
|
||||
|
||||
/// <summary>
|
||||
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="ImageIcon"/>.
|
||||
/// HCWhite <see cref="MarkupExtension"/> which can provide <see cref="ImageIcon"/>.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code lang="xml"> /// <ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Windows.Markup;
|
||||
namespace WPFluent.Markup;
|
||||
|
||||
/// <summary>
|
||||
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="SymbolIcon"/>.
|
||||
/// SymbolIcon <see cref="MarkupExtension"/> which can provide <see cref="SymbolIcon"/>.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code lang="xml"> /// <ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///
|
||||
|
||||
@@ -9,36 +9,46 @@ using WPFluent.Appearance;
|
||||
namespace WPFluent.Markup;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a dictionary implementation that contains <c>WPF UI</c> theme resources used by components and other
|
||||
/// 提供一个字典实现,其中包含组件和其他设备使用的 <c>WPF UI</c> 主题资源。
|
||||
/// elements of a WPF application.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <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>
|
||||
/// <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>
|
||||
/// </example>
|
||||
[Localizability(LocalizationCategory.Ignore)]
|
||||
[Ambient]
|
||||
[UsableDuringInitialization(true)]
|
||||
public class ThemesDictionary : ResourceDictionary
|
||||
{
|
||||
public ThemesDictionary() { SetSourceBasedOnSelectedTheme(ApplicationTheme.Light); }
|
||||
public ThemesDictionary() { SetSourceBasedOnSelectedTheme(ThemeType.Light); }
|
||||
|
||||
private void SetSourceBasedOnSelectedTheme(ApplicationTheme? selectedApplicationTheme)
|
||||
private void SetSourceBasedOnSelectedTheme(ThemeType? selectedApplicationTheme)
|
||||
{
|
||||
var themeName = selectedApplicationTheme switch
|
||||
{
|
||||
ApplicationTheme.Dark => "Dark",
|
||||
ThemeType.Light => "Light",
|
||||
ThemeType.Dark => "Dark",
|
||||
ThemeType.HcWhite => "HCWhite",
|
||||
ThemeType.HcBlack => "HCBlack",
|
||||
_ => "Light",
|
||||
};
|
||||
|
||||
Source = new Uri($"{ApplicationThemeManager.ThemesDictionaryPath}{themeName}.xaml", UriKind.Absolute);
|
||||
Source = new Uri($"{ThemeManager.ThemesDictionaryPath}{themeName}.xaml", UriKind.Absolute);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default application theme.
|
||||
/// </summary>
|
||||
public ApplicationTheme Theme { set => SetSourceBasedOnSelectedTheme(value); }
|
||||
public ThemeType Theme { set => SetSourceBasedOnSelectedTheme(value); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user