using System.Windows.Controls; // ReSharper disable once CheckNamespace namespace WPFluent.Controls; /// /// Represents an icon source that uses a glyph from the specified font. /// public class FontIconSource : IconSource { /// /// Identifies the dependency property. /// public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register( nameof(FontFamily), typeof(FontFamily), typeof(FontIconSource), new PropertyMetadata(SystemFonts.MessageFontFamily)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register( nameof(FontSize), typeof(double), typeof(FontIconSource), new PropertyMetadata(SystemFonts.MessageFontSize)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register( nameof(FontStyle), typeof(FontStyle), typeof(FontIconSource), new PropertyMetadata(FontStyles.Normal)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty FontWeightProperty = DependencyProperty.Register( nameof(FontWeight), typeof(FontWeight), typeof(FontIconSource), new PropertyMetadata(FontWeights.Normal)); /// /// Identifies the dependency property. /// 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; } /// public FontFamily FontFamily { get => (FontFamily)GetValue(FontFamilyProperty); set => SetValue(FontFamilyProperty, value); } /// public double FontSize { get => (double)GetValue(FontSizeProperty); set => SetValue(FontSizeProperty, value); } /// public FontStyle FontStyle { get => (FontStyle)GetValue(FontStyleProperty); set => SetValue(FontStyleProperty, value); } /// public FontWeight FontWeight { get => (FontWeight)GetValue(FontWeightProperty); set => SetValue(FontWeightProperty, value); } /// /// Gets or sets the character code that identifies the icon glyph. /// /// The hexadecimal character code for the icon glyph. public string Glyph { get => (string)GetValue(GlyphProperty); set => SetValue(GlyphProperty, value); } }