ItemTemplate in Silverlight ListBox being ignored
I have a databound ListBox with an ItemTemplate, following this example:
<ListBox ItemsSource="{Binding Path=FlightHeadings}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Identifier}" />
<TextBlock Text="{Binding Path=Name}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The ItemsSource databinding works; the ListBox displays all the items in the FlightHeadings property of the context.
However, the ItemTemplate is ignored. Instead of displaying each item as consisting of two TextBlocks, each item is instead displayed simply as its ToString() representation.
FWIW, I'm running Silverlight 4.0 on VS 2010, serving the test开发者_StackOverflow社区 page with Cassini. I suspect I'm missing something very simple in the above XAML but I can't tell what it is; any advice would be greatly appreciated.
Turns out that the XAML is okay; the issue is that an old build of the XAP file was being displayed.
Purging the browser cache, restarting the development web server, and restarting the browser fixed the problem.
精彩评论