Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何自定义列表框的布局';什么是模板?_Wpf_Expression Blend_Itemspaneltemplate - Fatal编程技术网

Wpf 如何自定义列表框的布局';什么是模板?

Wpf 如何自定义列表框的布局';什么是模板?,wpf,expression-blend,itemspaneltemplate,Wpf,Expression Blend,Itemspaneltemplate,我想为我的列表框指定多个列,但我的谷歌搜索技能在这一列上失败了 如何修改列表框的ItemsPanelTemplate,以自定义显示的列 编辑:忘记放我已经试过的东西了 我试过这个密码 <ItemsPanelTemplate x:Key="ItemsPanelTemplate1"> <UniformGrid Columns="3" /> </ItemsPanelTemplate> 除了我丢失了垂直滚动条外,这应该没那么难,但这取决于

我想为我的
列表框
指定多个列,但我的谷歌搜索技能在这一列上失败了

如何修改
列表框的
ItemsPanelTemplate
,以自定义显示的列

编辑:忘记放我已经试过的东西了

我试过这个密码

<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
        <UniformGrid Columns="3" />
    </ItemsPanelTemplate>


除了我丢失了垂直滚动条外,这应该没那么难,但这取决于-如果您对每个项目使用网格或类似控件,并且您不介意列的宽度不同,其中包含可变宽度的项目,那么只需向ItemTemplate添加网格即可

<ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition>
                <ColumnDefinition>
                <ColumnDefinition>
            </Grid.ColumnDefinitions>
            <SomeControl Grid.Column="0" />
            <SomeControl Grid.Column="1" />
            <SomeControl Grid.Column="2" />
        </Grid>
    </DataTemplate>
</ItemTemplate>


唯一的问题是,如果希望网格列的大小与可变大小的内容的大小相同(在这种情况下可能会涉及更多),否则可以显式设置大小,或者通过将列宽设置为“自动”,让内容决定大小

下面是一个简单的示例,我认为您正在寻找的内容包括3列、项目包装和自动垂直滚动,这将根据周围的布局来工作

<ListBox HorizontalContentAlignment="Stretch">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="3"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border MinHeight="150" Margin="5" Background="Green" CornerRadius="4">
                <TextBlock Text="{Binding}" Foreground="White"/>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>

    <System:String>One</System:String>
    <System:String>Two</System:String>
    <System:String>Three</System:String>
    <System:String>Four</System:String>
    <System:String>Five</System:String>
    <System:String>Six</System:String>
    <System:String>Seven</System:String>
    <System:String>Eight</System:String>
    <System:String>Nine</System:String>
    <System:String>Ten</System:String>
</ListBox>

一个
两个
三
四
五
六
七
八
九
十

您想为
列表框
修改
项目模板
的控件是什么?尽管这只是因为Blend为我自动生成的…我想在网格中显示列表中的项目,就像不太复杂的Zune唱片集艺术视图。您真的需要
列表框
的选择功能吗?如果没有,我建议切换到
ItemsControl
,我的博客上有一些例子,其中包括设置
ItemsPanelTemplate
我想要选择功能,是的-我打算将另一个控件绑定到ListBox。Selected属性以显示有关所选项目的更多详细信息您可以更具体地说明您对这些列所做的操作吗?您是在尝试在项目中设置多列,如DataGrid,还是尝试将项目本身水平布局,然后垂直包装?