views:

192

answers:

2

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

A: 

Try this:

<ListBox ItemsSource="{Binding FlightHeadings}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Identifier}" />
                <TextBlock Text="{Binding Name}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Rus
A: 

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.

Duncan Bayne
Were you using the Cassini development web server or IIS?
AnthonyWJones
Cassini - edited the original to specify that.
Duncan Bayne