46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System.Windows.Markup;
|
|
|
|
using WPFluent.Controls;
|
|
|
|
namespace WPFluent.Markup;
|
|
|
|
/// <summary>
|
|
/// FontIcon <see cref="MarkupExtension"/> which can provide <see cref="FontIcon"/>.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code lang="xml"> /// <ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///
|
|
/// Icon="{ui:FontIcon '🌈'}" /> ///</code> <code lang="xml"> /// <ui:Button Icon="{ui:FontIcon
|
|
/// '&#x1F308;'}" /> ///</code> <code lang="xml"> /// <ui:HyperlinkButton Icon="{ui:FontIcon '&#x1F308;'}"
|
|
/// /> ///</code> <code lang="xml"> /// <ui:TitleBar Icon="{ui:FontIcon '&#x1F308;'}" /> ///</code>
|
|
/// </example>
|
|
[ContentProperty(nameof(Glyph))]
|
|
[MarkupExtensionReturnType(typeof(FontIcon))]
|
|
public class FontIconExtension : MarkupExtension
|
|
{
|
|
public FontIconExtension()
|
|
{
|
|
}
|
|
|
|
public FontIconExtension(string glyph) { Glyph = glyph; }
|
|
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
{
|
|
FontIcon fontIcon = new() { Glyph = Glyph!, FontFamily = FontFamily };
|
|
|
|
if (FontSize > 0)
|
|
{
|
|
fontIcon.FontSize = FontSize;
|
|
}
|
|
|
|
return fontIcon;
|
|
}
|
|
|
|
[ConstructorArgument("fontFamily")]
|
|
public FontFamily FontFamily { get; set; } = new("FluentSystemIcons");
|
|
|
|
public double FontSize { get; set; }
|
|
|
|
[ConstructorArgument("glyph")]
|
|
public string? Glyph { get; set; }
|
|
}
|