2

ボタンのリストを生成するために、2 つの異なる 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>

2 番目の ItemsControl のボタンが新しい「行」に表示されます

ここに画像の説明を入力

2番目のItemsControlのボタンが最初のItemsControlのボタンの直後に表示される可能性はありますか? ボタンの数は異なる場合があります。次のようになります。

ここに画像の説明を入力

4

1 に答える 1

1

2 つのアイテム コレクションを 1 つにマージし、アイテムごとに適切な DataTemplate を返すItemTemplateSelector を持つItemsControlを 1 つだけ持つことができます。

于 2012-12-21T16:02:02.213 に答える