Percy
Percy

Reputation: 3125

How to programmatically create textblock using Segoe MDL2 Assets Font in WPF

I guess this should be easy, but instead of the icon I require, I get a bunch of square boxes.

Originally I was hard coding a menu in xaml:

code omitted
<ListBoxItem Name="menuHome" >
<StackPanel Orientation="Horizontal">
    <TextBlock FontFamily="Segoe MDL2 Assets" Text="&#xE10F;" FontSize="16" VerticalAlignment="Center" />
    <TextBlock Text="Home" FontSize="16" VerticalAlignment="Center" Padding="15,0,0,0"/>
</StackPanel>
</ListBoxItem>
code omitted

I now have to dynamically create this menu so I have the following:

ListBoxItem menuHome = new ListBoxItem();
StackPanel menuHomeStackPanel = new StackPanel() { Orientation = Orientation.Horizontal };
menuHomeStackPanel.Children.Add(new TextBlock() { FontFamily = new FontFamily("Segoe MDL2 Assets"), FontSize = 16, VerticalAlignment = VerticalAlignment.Center, Text = "&#xE10F;" });
menuHomeStackPanel.Children.Add(new TextBlock() { FontSize = 16, VerticalAlignment = VerticalAlignment.Center, Text = "Home", Padding = new Thickness(15, 0, 0, 0) });
menuHome.Content = menuHomeStackPanel;
menuHome.Name = "menuHome";
IconsListBox.Items.Add(menuHome);

This almost gives me the same except for the Segoe MDL2 Assets font which can be seen in the screenshot below:

screenshot

Any ideas - probably simple...?

Upvotes: 24

Views: 15131

Answers (2)

TERIHAX
TERIHAX

Reputation: 255

You can try this.

I'm pretty sure it would work:

Text = ""

Yep, it worked.

Upvotes: -2

Try this instead:

Text = "\xE10F" 

Upvotes: 55

Related Questions