I want to use some items in Segoe MDL2 Assets as icons for a menu driven off a collection.
I have my collection defined
NavItems = new ObservableCollection<NavItem>
{
new NavItem {Title = "Sign in", Icon="", ClassType = null },
new NavItem {Title = "Settings", Icon="", ClassType = typeof(Settings) }
};
In my xaml I have a listbox defined as
<ListBox ItemsSource="{Binding NavItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="24">
<ContentControl Content="{Binding Icon}" FontFamily="Segoe MDL2 Assets" />
<StackPanel Margin="20,0,0,0">
<TextBlock Text="{Binding Title}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The problem is when this listbox is rendered, the icons don't render properly (they show up as a bunch of squares). However if I replace the binding statement with the icon value directly in the xaml it works. I'm curious on how I would do this binding correctly.
(note I've tried various controls besides a generic content control with the same results so I know it's unrelated to that)
Many thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…