doerig
doerig

Reputation: 1857

Wrap Content of ItemsControls

I am using two different ItemsControl to generate a list of Buttons.

<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>

The buttons of the 2nd ItemsControl appear on a new "Line"

enter image description here

Is it possible that the Buttons of the 2nd ItemsControl appear directly after the Buttons from the first ItemsControl? The number of Buttons may vary. It should look like this:

enter image description here

Upvotes: 3

Views: 161

Answers (1)

Clemens
Clemens

Reputation: 128181

You could merge the two item collections into one and have only one ItemsControl with an ItemTemplateSelector that returns the appropriate DataTemplate for each item.

Upvotes: 1

Related Questions