整理控件库

This commit is contained in:
GG Z
2025-05-05 17:04:06 +08:00
parent 74532b77be
commit 3eaad7566e
283 changed files with 2156 additions and 17846 deletions

View File

@@ -1,112 +0,0 @@
namespace WPFluent.Markup;
/// <summary>
/// Custom design time attributes based on Marcin Najder implementation.
/// </summary>
/// <example>
/// <code lang="xml"> /// &lt;ui:FluentWindow /// xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" ///
/// ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" /// ui:Design.Foreground="{DynamicResource
/// TextFillColorPrimaryBrush}"&gt; /// &lt;Button Content="Hello World" /&gt; /// &lt;/FluentWindow&gt; ///</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);
}

View File

@@ -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"> /// &lt;ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///

View File

@@ -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"> /// &lt;ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///

View File

@@ -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"> /// &lt;ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///

View File

@@ -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"> /// &lt;Application /// xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"&gt; ///
/// &lt;Application.Resources&gt; /// &lt;ResourceDictionary&gt; ///
/// &lt;ResourceDictionary.MergedDictionaries&gt; /// &lt;ui:ThemesDictionary Theme = "Dark" /&gt; ///
/// &lt;/ResourceDictionary.MergedDictionaries&gt; /// &lt;/ResourceDictionary&gt; ///
/// &lt;/Application.Resources&gt; /// &lt;/Application&gt; ///</code>
/// <code lang="xml">
/// &lt;Application
/// xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"&gt;
/// &lt;Application.Resources&gt;
/// &lt;ResourceDictionary&gt;
/// &lt;ResourceDictionary.MergedDictionaries&gt;
/// &lt;ui:ThemesDictionary Theme = "Dark" /&gt;
/// &lt;/ResourceDictionary.MergedDictionaries&gt;
/// &lt;/ResourceDictionary&gt;
/// &lt;/Application.Resources&gt;
/// &lt;/Application&gt;
/// </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); }
}