2025-02-10 20:53:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System.Windows.Markup;
|
|
|
|
|
|
|
2025-07-11 09:20:23 +08:00
|
|
|
|
using WPFluent.Controls;
|
|
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
namespace WPFluent.Markup;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-05-05 17:04:06 +08:00
|
|
|
|
/// SymbolIcon <see cref="MarkupExtension"/> which can provide <see cref="SymbolIcon"/>.
|
2025-02-10 20:53:40 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <example>
|
|
|
|
|
|
/// <code lang="xml"> /// <ui:Button /// Appearance="Primary" /// Content="WPF UI button with font icon" ///
|
|
|
|
|
|
/// Icon="{ui:SymbolIcon Symbol=Fluent24}" /> ///</code> <code lang="xml"> /// <ui:Button Icon="{ui:SymbolIcon
|
|
|
|
|
|
/// Fluent24}" /> ///</code> <code lang="xml"> /// <ui:HyperlinkButton Icon="{ui:SymbolIcon Fluent24}" />
|
|
|
|
|
|
/// ///</code> <code lang="xml"> /// <ui:TitleBar Icon="{ui:SymbolIcon Fluent24}" /> ///</code>
|
|
|
|
|
|
/// </example>
|
|
|
|
|
|
[ContentProperty(nameof(Symbol))]
|
|
|
|
|
|
[MarkupExtensionReturnType(typeof(SymbolIcon))]
|
|
|
|
|
|
public class SymbolIconExtension : MarkupExtension
|
|
|
|
|
|
{
|
|
|
|
|
|
public SymbolIconExtension()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SymbolIconExtension(SymbolRegular symbol) { Symbol = symbol; }
|
|
|
|
|
|
|
|
|
|
|
|
public SymbolIconExtension(string symbol) { Symbol = (SymbolRegular)Enum.Parse(typeof(SymbolRegular), symbol); }
|
|
|
|
|
|
|
|
|
|
|
|
public SymbolIconExtension(SymbolRegular symbol, bool filled) : this(symbol) { Filled = filled; }
|
|
|
|
|
|
|
|
|
|
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
|
|
|
|
{
|
|
|
|
|
|
SymbolIcon symbolIcon = new(Symbol, filled: Filled);
|
|
|
|
|
|
|
|
|
|
|
|
if (FontSize > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
symbolIcon.FontSize = FontSize;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return symbolIcon;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ConstructorArgument("filled")]
|
|
|
|
|
|
public bool Filled { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public double FontSize { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[ConstructorArgument("symbol")]
|
|
|
|
|
|
public SymbolRegular Symbol { get; set; }
|
|
|
|
|
|
}
|