Search code examples
wpflistboxdatatemplatestackpanelitemtemplate

DataTemplate for Listbox containing lists as items doesn't get displayed


I have the following data template for a list box items:

<DataTemplate x:Key="substanceListShower">
    <ListBox ItemsSource="{Binding Items}">
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox>
</DataTemplate>

And then I apply the item template like this:

 ReactantInterfacesListBox.ItemTemplate = (DataTemplate)FindResource("substanceListShower");

But in the list for the items i get a ToString() return:

System.Windows.Controls.ItemsPanelTemplate

Any help would be appreciated.


Solution

  • You add an ItemsPanelTemplate to your ListBox, your definition lacks the ListBox.ItemsPanel tags to set the property instead.