整合自定义控件

This commit is contained in:
GG Z
2025-08-12 23:08:54 +08:00
parent f209e7d3ad
commit d0cfc64450
520 changed files with 30954 additions and 38968 deletions

View File

@@ -0,0 +1,13 @@
namespace WPFluent.Controls;
/// <summary>
/// Violeta Fluent Icons
/// https://github.com/emako/fluentui-violeta-icons
/// </summary>
public sealed class CustomFontSymbols
{
public const string Edit = "\xe900";
public const string Empty = "\xe901";
public const string Extension = "\xe902";
public const string File = "\xe903";
}

View File

@@ -0,0 +1,196 @@
using System.Windows.Controls;
using System.Windows.Documents;
using FontFamily = System.Windows.Media.FontFamily;
using FontStyle = System.Windows.FontStyle;
using SystemFonts = System.Windows.SystemFonts;
// ReSharper disable once CheckNamespace
namespace WPFluent.Controls;
/// <summary>
/// Represents an icon that uses a glyph from the specified font.
/// </summary>
public class FontIcon : IconElement
{
/// <summary>
/// Identifies the <see cref="FontFamily"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(
nameof(FontFamily),
typeof(FontFamily),
typeof(FontIcon),
new FrameworkPropertyMetadata(new FontFamily("Segoe MDL2 Assets"), OnFontFamilyChanged));
/// <summary>
/// Identifies the <see cref="FontSize"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontSizeProperty = TextElement.FontSizeProperty
.AddOwner(
typeof(FontIcon),
new FrameworkPropertyMetadata(
SystemFonts.MessageFontSize,
FrameworkPropertyMetadataOptions.Inherits,
OnFontSizeChanged));
/// <summary>
/// Identifies the <see cref="FontStyle"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register(
nameof(FontStyle),
typeof(FontStyle),
typeof(FontIcon),
new FrameworkPropertyMetadata(FontStyles.Normal, OnFontStyleChanged));
/// <summary>
/// Identifies the <see cref="FontWeight"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontWeightProperty = DependencyProperty.Register(
nameof(FontWeight),
typeof(FontWeight),
typeof(FontIcon),
new FrameworkPropertyMetadata(FontWeights.Normal, OnFontWeightChanged));
/// <summary>
/// Identifies the <see cref="Glyph"/> dependency property.
/// </summary>
public static readonly DependencyProperty GlyphProperty = DependencyProperty.Register(
nameof(Glyph),
typeof(string),
typeof(FontIcon),
new FrameworkPropertyMetadata(string.Empty, OnGlyphChanged));
private static void OnFontFamilyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (FontIcon)d;
if (self.TextBlock is null)
{
return;
}
self.TextBlock.SetCurrentValue(System.Windows.Controls.TextBlock.FontFamilyProperty, (FontFamily)e.NewValue);
}
private static void OnFontSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (FontIcon)d;
if (self.TextBlock is null)
{
return;
}
self.TextBlock.SetCurrentValue(System.Windows.Controls.TextBlock.FontSizeProperty, (double)e.NewValue);
}
private static void OnFontStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (FontIcon)d;
if (self.TextBlock is null)
{
return;
}
self.TextBlock.SetCurrentValue(System.Windows.Controls.TextBlock.FontStyleProperty, (FontStyle)e.NewValue);
}
private static void OnFontWeightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (FontIcon)d;
if (self.TextBlock is null)
{
return;
}
self.TextBlock.SetCurrentValue(System.Windows.Controls.TextBlock.FontWeightProperty, (FontWeight)e.NewValue);
}
private static void OnGlyphChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (FontIcon)d;
if (self.TextBlock is null)
{
return;
}
self.TextBlock.SetCurrentValue(System.Windows.Controls.TextBlock.TextProperty, (string)e.NewValue);
}
protected override UIElement InitializeChildren()
{
if (FontSize.Equals(SystemFonts.MessageFontSize))
{
// SetResourceReference(FontSizeProperty, "DefaultIconFontSize");
// If the FontSize is the default, set it to the parent's FontSize.
if (VisualParent is not null && TextElement.GetFontSize(VisualParent) != SystemFonts.MessageFontSize)
{
SetCurrentValue(FontSizeProperty, TextElement.GetFontSize(VisualParent));
}
}
TextBlock = new TextBlock
{
Style = null,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Center,
TextAlignment = TextAlignment.Center,
FontFamily = FontFamily,
FontSize = FontSize,
FontStyle = FontStyle,
FontWeight = FontWeight,
Text = Glyph,
Visibility = Visibility.Visible,
Focusable = false,
};
SetCurrentValue(FocusableProperty, false);
return TextBlock;
}
protected TextBlock? TextBlock { get; set; }
/// <inheritdoc cref="Control.FontFamily"/>
[Bindable(true)]
[Category("Appearance")]
[Localizability(LocalizationCategory.Font)]
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
/// <inheritdoc cref="Control.FontSize"/>
[TypeConverter(typeof(FontSizeConverter))]
[Bindable(true)]
[Category("Appearance")]
[Localizability(LocalizationCategory.None)]
public double FontSize { get => (double)GetValue(FontSizeProperty); set => SetValue(FontSizeProperty, value); }
/// <inheritdoc cref="Control.FontStyle"/>
[Bindable(true)]
[Category("Appearance")]
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
/// <inheritdoc cref="Control.FontWeight"/>
[Bindable(true)]
[Category("Appearance")]
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
/// <summary>
/// Gets or sets the character code that identifies the icon glyph.
/// </summary>
/// <returns>The hexadecimal character code for the icon glyph.</returns>
public string Glyph { get => (string)GetValue(GlyphProperty); set => SetValue(GlyphProperty, value); }
}

View File

@@ -0,0 +1,26 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WPFluent.Controls;
// TODO: Use font icon if available
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class FontIconFallback : Control
{
static FontIconFallback()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(FontIconFallback), new FrameworkPropertyMetadata(typeof(FontIconFallback)));
FocusableProperty.OverrideMetadata(typeof(FontIconFallback), new FrameworkPropertyMetadata(false));
}
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register(nameof(Data), typeof(Geometry), typeof(FontIconFallback), null);
public Geometry Data
{
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
}

View File

@@ -0,0 +1,29 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFluent.Controls">
<Style TargetType="local:FontIconFallback">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:FontIconFallback">
<Viewbox
Width="{TemplateBinding FontSize}"
Height="{TemplateBinding FontSize}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Path
Width="20"
Height="20"
Data="{TemplateBinding Data}"
Fill="{TemplateBinding Foreground}" />
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,120 @@
using System.Windows.Controls;
// ReSharper disable once CheckNamespace
namespace WPFluent.Controls;
/// <summary>
/// Represents an icon source that uses a glyph from the specified font.
/// </summary>
public class FontIconSource : IconSource
{
/// <summary>
/// Identifies the <see cref="FontFamily"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(
nameof(FontFamily),
typeof(FontFamily),
typeof(FontIconSource),
new PropertyMetadata(SystemFonts.MessageFontFamily));
/// <summary>
/// Identifies the <see cref="FontSize"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register(
nameof(FontSize),
typeof(double),
typeof(FontIconSource),
new PropertyMetadata(SystemFonts.MessageFontSize));
/// <summary>
/// Identifies the <see cref="FontStyle"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register(
nameof(FontStyle),
typeof(FontStyle),
typeof(FontIconSource),
new PropertyMetadata(FontStyles.Normal));
/// <summary>
/// Identifies the <see cref="FontWeight"/> dependency property.
/// </summary>
public static readonly DependencyProperty FontWeightProperty = DependencyProperty.Register(
nameof(FontWeight),
typeof(FontWeight),
typeof(FontIconSource),
new PropertyMetadata(FontWeights.Normal));
/// <summary>
/// Identifies the <see cref="Glyph"/> dependency property.
/// </summary>
public static readonly DependencyProperty GlyphProperty = DependencyProperty.Register(
nameof(Glyph),
typeof(string),
typeof(FontIconSource),
new PropertyMetadata(string.Empty));
public override IconElement CreateIconElement()
{
var fontIcon = new FontIcon() { Glyph = Glyph };
if(!Equals(FontFamily, SystemFonts.MessageFontFamily))
{
fontIcon.FontFamily = FontFamily;
}
if(!FontSize.Equals(SystemFonts.MessageFontSize))
{
fontIcon.FontSize = FontSize;
}
if(FontWeight != FontWeights.Normal)
{
fontIcon.FontWeight = FontWeight;
}
if(FontStyle != FontStyles.Normal)
{
fontIcon.FontStyle = FontStyle;
}
if(Foreground != SystemColors.ControlTextBrush)
{
fontIcon.Foreground = Foreground;
}
return fontIcon;
}
/// <inheritdoc cref="Control.FontFamily"/>
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
/// <inheritdoc cref="Control.FontSize"/>
public double FontSize { get => (double)GetValue(FontSizeProperty); set => SetValue(FontSizeProperty, value); }
/// <inheritdoc cref="Control.FontStyle"/>
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
/// <inheritdoc cref="Control.FontWeight"/>
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
/// <summary>
/// Gets or sets the character code that identifies the icon glyph.
/// </summary>
/// <returns>The hexadecimal character code for the icon glyph.</returns>
public string Glyph { get => (string)GetValue(GlyphProperty); set => SetValue(GlyphProperty, value); }
}

File diff suppressed because it is too large Load Diff