using WPFluent.Extensions;
// ReSharper disable once CheckNamespace
namespace WPFluent.Controls;
///
/// Represents a text element containing an icon glyph.
///
public class SymbolIcon : FontIcon
{
///
/// Identifies the dependency property.
///
public static readonly DependencyProperty SymbolProperty = DependencyProperty.Register(
nameof(Symbol),
typeof(SymbolRegular),
typeof(SymbolIcon),
new PropertyMetadata(SymbolRegular.Empty, static (o, _) => ((SymbolIcon)o).OnGlyphChanged()));
///
/// Identifies the dependency property.
///
public static readonly DependencyProperty FilledProperty = DependencyProperty.Register(
nameof(Filled),
typeof(bool),
typeof(SymbolIcon),
new PropertyMetadata(false, OnFilledChanged));
public SymbolIcon()
{
}
public SymbolIcon(SymbolRegular symbol, double fontSize = 14, bool filled = false)
{
Symbol = symbol;
Filled = filled;
FontSize = fontSize;
}
private static void OnFilledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (SymbolIcon)d;
self.SetFontReference();
self.OnGlyphChanged();
}
private void OnGlyphChanged()
{
if (Filled)
{
SetCurrentValue(GlyphProperty, Symbol.Swap().GetString());
}
else
{
SetCurrentValue(GlyphProperty, Symbol.GetString());
}
}
private void SetFontReference()
{ SetResourceReference(FontFamilyProperty, Filled ? "FluentSystemIconsFilled" : "FluentSystemIcons"); }
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
SetFontReference();
}
///
/// Gets or sets a value indicating whether or not we should use the .
///
public bool Filled { get => (bool)GetValue(FilledProperty); set => SetValue(FilledProperty, value); }
///
/// Gets or sets displayed .
///
public SymbolRegular Symbol
{
get => (SymbolRegular)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}
}