我正在使用两个不同的 ItemsControl 来生成一个按钮列表。
<WrapPanel Orientation="Horizontal">
<ItemsControl ItemsSource="{Binding Commands}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding}">
<!-- ... -->
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl ItemsSource="{Binding CurrentTransaction.Modifiers}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton IsChecked="{Binding IsEnabled}">
<!-- ... -->
</ToggleButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</WrapPanel>
第二个 ItemsControl 的按钮出现在新的“行”上
是否有可能第二个 ItemsControl 的按钮直接出现在第一个 ItemsControl 的按钮之后?按钮的数量可能会有所不同。它应该看起来像这样:
最佳答案
您可以将两个项目集合合并为一个,并且只有一个带有 ItemTemplateSelector 的 ItemsControl。为每个项目返回适当的 DataTemplate。
关于.net - 包装 ItemsControls 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13992633/