好的,这看起来是一个非常简单的问题,但却让我发疯。我正在学习DataTemplating,并试图将一个非常非常简单的ItemTemplate应用于ListBox。
然而,当我运行我的应用程序时,模板完全被忽略了,我只看到标准的ListBox,而实际上我期望看到一列带有“Test”旁边复选框的列表。
我已经尝试了几次,结果总是一样。我检查了谷歌上的几个资源,所有的资源都有相同的语法用于在ListBox上定义ItemTemplate,所以我真的看不出我哪里错了。
代码...
<Grid x:Name="LayoutRoot">
<ListBox x:Name="TestList"
SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox Content="Check this checkbox!"/>
<TextBlock>Test</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Items>
<ListBoxItem>Bob</ListBoxItem>
<ListBoxItem>Jim</ListBoxItem>
<ListBoxItem>Dave</ListBoxItem>
<ListBoxItem>Larry</ListBoxItem>
<ListBoxItem>Tom</ListBoxItem>
</ListBox.Items>
</ListBox>
</Grid>
非常感谢任何帮助。对于这样一个看起来很愚蠢的问题,我表示歉意,但是我在这里遇到了第一个障碍 :(AT