我正在尝试制作一个包含自定义控件的列表框,它可以像下面这样包装automic.My列表框xaml代码,我需要在每一行中放置三项,如果项超过三项,则扩展到最大的width.It将被包装到下一行。我需要我的自定义控制伸展在水平,而不是所有的一边。我怎么能这么做?
<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>发布于 2015-04-23 07:37:34
使用具有三列的UniformGrid作为ItemsPanel
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3" VerticalAlignment="Top"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
...
</ListBox>您还可以在TransducerItem的ItemTemplate of ListBox中使用ListBox控件。
<ListBox.ItemTemplate>
<DataTemplate>
<controls:TransducerItem Margin="5,10"/>
</DataTemplate>
</ListBox.ItemTemplate>然后将ListBox的ItemsSource属性绑定到保存每个TransducerItem数据的数据项集合:
<ListBox ItemsSource="{Binding TranducerData}">
...
</ListBox>看看MSDN上的数据模板概述文章。
https://stackoverflow.com/questions/29816376
复制相似问题