Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

xaml

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...?

like image 950
Percy Avatar asked Jan 11 '16 15:01

Percy


1 Answers

Try this instead:

Text = "\xE10F" 
like image 81
15ee8f99-57ff-4f92-890c-b56153 Avatar answered Nov 14 '22 10:11

15ee8f99-57ff-4f92-890c-b56153