113 lines
3.5 KiB
C#
113 lines
3.5 KiB
C#
using System.Windows.Controls;
|
|
|
|
|
|
namespace WPFluent.Controls;
|
|
|
|
/// <summary>
|
|
/// Represents an icon source that uses a glyph from the specified font.
|
|
/// </summary>
|
|
public class SymbolIconSource : IconSource
|
|
{
|
|
/// <summary>
|
|
/// Identifies the <see cref="Filled"/> dependency property.
|
|
/// </summary>
|
|
public static readonly DependencyProperty FilledProperty = DependencyProperty.Register(
|
|
nameof(Filled),
|
|
typeof(bool),
|
|
typeof(SymbolIconSource),
|
|
new PropertyMetadata(false));
|
|
/// <summary>
|
|
/// Identifies the <see cref="FontSize"/> dependency property.
|
|
/// </summary>
|
|
public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register(
|
|
nameof(FontSize),
|
|
typeof(double),
|
|
typeof(SymbolIconSource),
|
|
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(SymbolIconSource),
|
|
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(SymbolIconSource),
|
|
new PropertyMetadata(FontWeights.Normal));
|
|
|
|
/// <summary>
|
|
/// Identifies the <see cref="Symbol"/> dependency property.
|
|
/// </summary>
|
|
public static readonly DependencyProperty SymbolProperty = DependencyProperty.Register(
|
|
nameof(Symbol),
|
|
typeof(SymbolRegular),
|
|
typeof(SymbolIconSource),
|
|
new PropertyMetadata(SymbolRegular.Empty));
|
|
|
|
public override IconElement CreateIconElement()
|
|
{
|
|
SymbolIcon symbolIcon = new(Symbol, FontSize, Filled);
|
|
|
|
if (!FontSize.Equals(SystemFonts.MessageFontSize))
|
|
{
|
|
symbolIcon.FontSize = FontSize;
|
|
}
|
|
|
|
if (FontWeight != FontWeights.Normal)
|
|
{
|
|
symbolIcon.FontWeight = FontWeight;
|
|
}
|
|
|
|
if (FontStyle != FontStyles.Normal)
|
|
{
|
|
symbolIcon.FontStyle = FontStyle;
|
|
}
|
|
|
|
if (Foreground != SystemColors.ControlTextBrush)
|
|
{
|
|
symbolIcon.Foreground = Foreground;
|
|
}
|
|
|
|
return symbolIcon;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether or not we should use the <see cref="SymbolFilled"/>.
|
|
/// </summary>
|
|
public bool Filled { get => (bool)GetValue(FilledProperty); set => SetValue(FilledProperty, 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 displayed <see cref="SymbolRegular"/>.
|
|
/// </summary>
|
|
public SymbolRegular Symbol
|
|
{
|
|
get => (SymbolRegular)GetValue(SymbolProperty);
|
|
set => SetValue(SymbolProperty, value);
|
|
}
|
|
}
|