首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ContentPresenter与ListBox

ContentPresenter与ListBox
EN

Stack Overflow用户
提问于 2011-07-28 03:06:20
回答 1查看 3.6K关注 0票数 3

我正在尝试对我的ItemsControl使用单一选择模式。所以我把我的ItemsControl变成了ListBox,但是我得到了一个异常

“用于类型'ContentPresenter‘的样式不能应用于’ListBoxItem‘类型。”

上面有什么?我不能用ContentPresenter做ListBoxes吗?

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-28 03:37:08

样式需要以ListBoxItem为目标,因为这总是要创建的。一些更多的ListBox模板和数据板文档和示例可以找到这里

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6853679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档