Coder Social home page Coder Social logo

Comments (2)

davidxuang avatar davidxuang commented on July 22, 2024 1

Implemented in 52a57f6.

烦请测试,若实现有缺漏欢迎 re-open.

from fluenticons.

Poker-sang avatar Poker-sang commented on July 22, 2024

写了一个简单的例子可供参考【

/// <summary>
/// An abstract <see cref="MarkupExtension"/> which to produce text-based icons.
/// </summary>
public abstract class SymbolIconBaseExtension : MarkupExtension
{
    /// <summary>
    /// Gets or sets if the icon is filled.
    /// </summary>
    public bool IsFilled { get; set; }

    /// <summary>
    /// Gets or sets if the icon use Segoe metrics.
    /// </summary>
    public bool UseSegoeMetrics { get; set; }

    /// <summary>
    /// Gets or sets the size of the icon to display.
    /// </summary>
    public double FontSize { get; set; }

    /// <summary>
    /// Gets or sets the symbol of the icon to display.
    /// </summary>
    public Symbol Symbol { get; set; }

    /// <summary>
    /// Gets or sets the size of the icon to display. Priority is higher than <see cref="FontSize"/>.
    /// </summary>
    public FontSizeType Size { get; set; }

    /// <summary>
    /// Gets or sets the thickness of the icon glyph.
    /// </summary>
    public FontWeight FontWeight { get; set; } = FontWeights.Normal;

    /// <summary>
    /// Gets or sets the font style for the icon glyph.
    /// </summary>
    public FontStyle FontStyle { get; set; } = FontStyle.Normal;

    /// <summary>
    /// Gets or sets the foreground <see cref="Brush"/> for the icon.
    /// </summary>
    public Brush? Foreground { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled.
    /// </summary>
    public bool IsTextScaleFactorEnabled { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left.
    /// </summary>
    public bool MirroredWhenRightToLeft { get; set; }
}


/// <summary>
/// Symbol icon source markup extension
/// </summary>
[MarkupExtensionReturnType(ReturnType = typeof(SymbolIconSource))]
public class SymbolIconSourceExtension : SymbolIconBaseExtension
{
    /// <inheritdoc />
    protected override object ProvideValue()
    {
        var icon = new SymbolIconSource
        {
            IsFilled = IsFilled,
            UseSegoeMetrics = UseSegoeMetrics,
            Symbol = Symbol,
            FontWeight = FontWeight,
            FontStyle = FontStyle,
            IsTextScaleFactorEnabled = IsTextScaleFactorEnabled,
            MirroredWhenRightToLeft = MirroredWhenRightToLeft
        };

        if (Size is not FontSizeType.None)
            icon.FontSize = (int)Size;
        else if (FontSize > 0)
            icon.FontSize = FontSize;

        if (Foreground is not null)
            icon.Foreground = Foreground;

        return icon;
    }
}

/// <summary>
/// Symbol icon markup extension
/// </summary>
[MarkupExtensionReturnType(ReturnType = typeof(SymbolIcon))]
public class SymbolIconExtension : SymbolIconBaseExtension
{
    /// <inheritdoc cref="FrameworkElement.FlowDirection"/>
    public FlowDirection FlowDirection { get; set; }

    /// <inheritdoc />
    protected override object ProvideValue()
    {
        var icon = new SymbolIcon
        {
            IsFilled = IsFilled,
            UseSegoeMetrics = UseSegoeMetrics,
            Symbol = Symbol,
            FontWeight = FontWeight,
            FontStyle = FontStyle,
            IsTextScaleFactorEnabled = IsTextScaleFactorEnabled,
            MirroredWhenRightToLeft = MirroredWhenRightToLeft,
            FlowDirection = FlowDirection
        };

        if (Size is not FontSizeType.None)
            icon.FontSize = (int)Size;
        else if (FontSize > 0)
            icon.FontSize = FontSize;

        if (Foreground is not null)
            icon.Foreground = Foreground;

        return icon;
    }
}

/// <summary>
/// Font size
/// </summary>
/// <remarks>
/// <see href="https://learn.microsoft.com/windows/apps/design/style/segoe-fluent-icons-font"/>
/// </remarks>
public enum FontSizeType
{
    /// <summary>
    /// Use FontSize property
    /// </summary>
    None = 0,

    /// <summary>
    /// 16
    /// </summary>
    Small = 16,

    /// <summary>
    /// 20
    /// </summary>
    Normal = 20,

    /// <summary>
    /// 24
    /// </summary>
    Large = 24,

    /// <summary>
    /// 32
    /// </summary>
    ExLarge = 32,

    /// <summary>
    /// 48
    /// </summary>
    ExExLarge = 48,

    /// <summary>
    /// 64
    /// </summary>
    ExExExLarge = 64
}

from fluenticons.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.