好吧,这是一个令人尴尬的简单问题,但让我发疯.我正在学习DataTemplating,并且我正在尝试将非常简单的ItemTemplate应用于ListBox.
但是,当我运行我的应用程序时,模板完全被忽略,我只是得到标准的列表框,而实际上我希望看到一个带有'Test'的复选框列表.
我已经尝试过几次并且总是一样的结果.我在Google上查了几个资源,并且在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>
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢.抱歉这样一个看似愚蠢的问题,但我真的堕落在这里的第一个障碍:(
在