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