andreinitescu / IconFont2Code

Generate C# class with constant fields for the icons in your font
277 stars 37 forks source link

How to call it from xaml? #5

Closed grayter1 closed 4 years ago

grayter1 commented 4 years ago

How to call item from generated list in xaml? I have following class:

static class IconFontCollection
{
    public const string SlashForward = "\u000f0000";
    public const string SlashForwardBox = "\u000f0001";
    public const string SwapHorizontalCircle = "\u000f0002";
    public const string SwapHorizontalCircleOutline = "\u000f0003";
}

An how should I use it in xaml? <Button Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="2" StyleClass="ActionButton" Text="do smth">

    <Button.ImageSource>
        <FontImageSource
                FontFamily="{StaticResource IconFont}"
                Size="20"
                Color="{StaticResource BaseColor}"
                Glyph="{Binding IconFontCollection.SlashForward "/> //??
    </Button.ImageSource>
</Button>

Regards

andreinitescu commented 4 years ago

Try with x:Static instead of Binding:

Glyph="{x:Static yourNamespace:IconFontCollection.SlashForward}

You also need to declare x:yourNamespace namespace at the top of xaml

Please use StackOverflow to ask questions about Xamarin.Forms and XAML. This is a place only for issues related to the IconFont2Code tool. Thanks!