优化更新代码,添加界面功能并整合
This commit is contained in:
48
WPFluent/Markup/FontIconExtension.cs
Normal file
48
WPFluent/Markup/FontIconExtension.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace WPFluent.Markup;
|
||||
|
||||
/// <summary>
|
||||
/// Custom <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; }
|
||||
}
|
||||
Reference in New Issue
Block a user