我正在尝试对我的ItemsControl使用单一选择模式。所以我把我的ItemsControl变成了ListBox,但是我得到了一个异常
“用于类型'ContentPresenter‘的样式不能应用于’ListBoxItem‘类型。”
上面有什么?我不能用ContentPresenter做ListBoxes吗?
<ListBox SelectionMode="Single" ItemsSource="{Binding}" MinHeight="200" MinWidth="200">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid></UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Grid.Row" Value="{Binding X}" />
<Setter Property="Grid.Column" Value="{Binding Y}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate DataType="ObservableCollection">
<Border BorderBrush="Black" BorderThickness="0.5" Background="Beige">
<clr:Cell Content="{Binding Character}"></clr:Cell>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>发布于 2011-07-28 03:37:08
样式需要以ListBoxItem为目标,因为这总是要创建的。一些更多的ListBox模板和数据板文档和示例可以找到这里。
https://stackoverflow.com/questions/6853679
复制相似问题