I'm filling a ListBox with items from a bound model. While testing I had this:
<ListBox x:Name="SettingsHolder" Margin="5,8,5,5" ItemsSource="{Binding AllSettingItems}" Height="380" DisplayMemberPath="Display"/>
By binding directly to a member of item objects in ItemsSource, I was able to see I was loading the list box properly. In fact, the 'Display' member is just a String.Format of the members I'd like to display using a DataTemplate. Everything works great. Should be no big deal to define a template, right?
So, then I defined my data template.
<Window.Resources>
<DataTemplate x:Key="AllSettingsItemTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="140*"/>
<ColumnDefinition Width="16"/>
<ColumnDefinition Width="16"/>
<ColumnDefinition Width="16"/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" DataContext="{Binding Key}"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Grid.Column="1" DataContext="{Binding DevDisplay}"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Grid.Column="2" DataContext="{Binding CertDisplay}"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Grid.Column="3" DataContext="{Binding ProdDisplay}"/>
</Grid>
</DataTemplate>
</Window.Resources>
I removed the DisplayMemberPath.
I substituted:
ItemTemplate="{DynamicResource AllSettingsItemTemplate}"
And now, no values are displayed. I can tell by the appearance of scroll bars, and selectable members that the AllSettingsItem values are being bound, because I get the correct NUMBER of selectable item, but nothing is displayed. It's as if the binding to the item members (Key, DevDisplay, etc.) just isn't happening, or if it is happening, it isn't being rendered.
I've tried Path=Key in the data-template binding. It was a shot in the dark so . . .
What's the secret? How do you even debug something like this?
(I'm using Blend and VS2013).
You're not binding the
Text
of theTextBlock
to anything. Try something like this:FYI, the
DataTemplate
'sDataContext
is automatically set to the item that it is binding to.