Home > Mobile >  How to use a font unicode that is stored in c#
How to use a font unicode that is stored in c#

Time:09-06

I have a list of objects called SidebarItems, this list may change according to what Module the user is in. I have downloaded and got Font Awesome Pro working in my application, However I must use the Unacode to access the correct icon inside the font.

The SidebarNavItem

public record SidebarNavItem(string Title, string ViewName, string IconUnicode);
public class SidebarItems:IReadOnlyCollection<SidebarNavItem>
{
   //Left this out for brevity
}

The Xaml That its being used

<Button Style="{StaticResource LabeledIconButton}" 
        Content="{Binding IconUnicode}" Grid.Row="0" 
        behaviors:ButtonBehavior.Label="{Binding Title}"
        Command="{Binding NavigateCommand}" 
        CommandParameter="{Binding ViewName}"/>

enter image description here

This is what I'm getting but when I type it into the button, I get this:

<Button Style="{StaticResource LabeledIconButton}" 
        Content="&#xf319;" Grid.Row="0" 
        behaviors:ButtonBehavior.Label="{Binding Title}"
        Command="{Binding NavigateCommand}" 
        CommandParameter="{Binding ViewName}"/>

enter image description here

How can I store these codes in SidebarItems?

CodePudding user response:

Replace &#x with \u and remove the trailing ; from the string value returned from the property.

So &#xf319; becomes:

public string IconUnicode => "\uf319";
  • Related