包含列表作为项目的Listbox的DataTemplate不会显示

时间:2012-02-09 23:40:44

标签: wpf listbox datatemplate stackpanel itemtemplate

我有一个列表框项目的以下数据模板:

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

然后我按照以下方式应用项目模板:

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

但是在我获得ToString()的项目列表中返回:

System.Windows.Controls.ItemsPanelTemplate

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您向ItemsPanelTemplate添加了ListBox,您的定义缺少ListBox.ItemsPanel代码来设置属性。