How to have a user control as a ListBoxItem
- by Harry
I want to bind a user control (View) to a ListBoxItem. The ListBox is bound to a collection of ViewModels. I have set the ListBox's ItemTemplate as so:
<ListBox.ItemTemplate>
<DataTemplate>
<View:ContactView/>
</DataTemplate>
</ListBox.ItemTemplate>
But all I get are blank ListBoxItems. I can click on them, but nothing is showing visually. My ContactView code is very simply:
<Border>
<DockPanel>
<StackPanel DockPanel.Dock="Right" Orientation="Vertical">
<TextBlock Text="{Binding Path=ContactFirstName, FallbackValue=FirstName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock>
<TextBlock Text="{Binding Path=ContactLastName, FallbackValue=LastName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock>
<TextBlock Text="{Binding Path=ContactNumber, FallbackValue=Number}" Margin="5, 0, 5, 0"></TextBlock>
</StackPanel>
</DockPanel>
</Border>
What could be wrong with this? Thanks.