首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF ListBoxItem在WPF中没有最大宽度。

WPF ListBoxItem在WPF中没有最大宽度。
EN

Stack Overflow用户
提问于 2015-04-23 07:20:12
回答 1查看 300关注 0票数 0

我正在尝试制作一个包含自定义控件的列表框,它可以像下面这样包装automic.My列表框xaml代码,我需要在每一行中放置三项,如果项超过三项,则扩展到最大的width.It将被包装到下一行。我需要我的自定义控制伸展在水平,而不是所有的一边。我怎么能这么做?

代码语言:javascript
复制
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
            <ListBox>
                <ListBox.Template>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <WrapPanel Orientation="Horizontal" IsItemsHost="True" />
                    </ControlTemplate>
                </ListBox.Template>

                <ListBoxItem>
                    <controls:TransducerItem  Margin="5,10"/>
                </ListBoxItem>

                <ListBoxItem>
                    <controls:TransducerItem  Margin="5,10"/>
                </ListBoxItem>


                <ListBoxItem>
                    <controls:TransducerItem  Margin="5,10"/>
                </ListBoxItem>

                <ListBoxItem>
                    <controls:TransducerItem Margin="5,10" />
                </ListBoxItem>

                <ListBoxItem>
                    <controls:TransducerItem  Width="200" Margin="5,10" />
                </ListBoxItem>
            </ListBox>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-23 07:37:34

使用具有三列的UniformGrid作为ItemsPanel

代码语言:javascript
复制
<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="3" VerticalAlignment="Top"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    ...
</ListBox>

您还可以在TransducerItem的ItemTemplate of ListBox中使用ListBox控件。

代码语言:javascript
复制
<ListBox.ItemTemplate>
    <DataTemplate>
        <controls:TransducerItem  Margin="5,10"/>  
    </DataTemplate>
</ListBox.ItemTemplate>

然后将ListBox的ItemsSource属性绑定到保存每个TransducerItem数据的数据项集合:

代码语言:javascript
复制
<ListBox ItemsSource="{Binding TranducerData}">
    ...
</ListBox>

看看MSDN上的数据模板概述文章。

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

https://stackoverflow.com/questions/29816376

复制
相关文章

相似问题

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