.net - 包装 ItemsControls 的内容

标签 .net wpf xaml itemscontrol

我正在使用两个不同的 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 的按钮出现在新的“行”上

enter image description here

是否有可能第二个 ItemsControl 的按钮直接出现在第一个 ItemsControl 的按钮之后?按钮的数量可能会有所不同。它应该看起来像这样:

enter image description here

最佳答案

您可以将两个项目集合合并为一个,并且只有一个带有 ItemTemplateSelector 的 ItemsControl。为每个项目返回适当的 DataTemplate。

关于.net - 包装 ItemsControls 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13992633/

相关文章:

c# - 在 C# 中使用动态绑定(bind)代替严格类型值的扩展方法

c# - 无法从 'System.Collections.Generic.IEnumerable<char>' 转换为 'string'

c# - FlowDocumentScrollViewer FontSize 不会改变 FlowDocument 内容的 FontSize

wpf - 如何仅使用 XAML 而不使用隐藏代码对 ListBox 进行排序?

c# - 在 xaml 4.5+ 中创建通用列表

c# - 为什么UserControl文本 block 在设计模式下振动

c# - 监听另一台服务器的最简单方法?

c# - 如何从单独的进程监视应用程序崩溃

c# - 绑定(bind)内部绑定(bind) WPF

wpf - XAML:如何将 GroupBox Header 的一部分设为粗体?