祝大家新年快乐!感谢你阅读这篇文章!
我在为contentTemplate定位动态内容时遇到了问题,我有以下几点:
<TabControl ItemsSource="{Binding Cats}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" FontSize="16" FontWeight="Bold"></TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<WrapPanel>
<ItemsControl ItemsSource="{Binding Products}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}" Height="25" Width="100"></Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</WrapPanel>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>itemsSource绑定猫返回一个类别列表,并且在每个类别中都有一个属性返回产品列表

目前正在显示所有垂直堆叠的按钮,但我需要的按钮来填充wrapPanel。下面是我要找的contentTemplate的图示:

任何想法都将不胜感激!
发布于 2012-01-04 22:07:10
您需要使用WrapPanel作为ItemsPanel模板。有关参考,请参阅this问题。基本上,您需要将此XAML添加到:
<ItemsControl ItemsSource="{Binding Products}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}" Height="25" Width="100"></Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>注意:您实际上不需要设置WrapPanel的Orientation属性,它只是为了显式。
https://stackoverflow.com/questions/8727962
复制相似问题