Using StackPanel as ContentControl (WPF)

So, I have a StackPanel which I use as ContentControl. I have a place where I want the buttons to be created based on the data that I attach to, and this all works well, but I want the buttons to be laid out horizontally and not vertically, as is currently the case. Here is a screenshot:

alt text

And here is the code from my ContentTemplate description:

<StackPanel Name="wpReleaseButtons" Orientation="Horizontal" Grid.Row="2">
    <ItemsControl IsTabStop="False" ItemsSource="{Binding Path=BranchCommands}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Button Tag="{Binding}" Padding="3">
                     <TextBlock Text="{Binding Path=DisplayValue}" />
                </Button>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>

Not sure what I'm doing wrong here. Any information would be greatly appreciated. Thanks!

+5
source share
2 answers

, , ItemsControl - , . , ItemsControl , StackPanel ItemsControl ItemsPanelTemplate, , , :

<ItemsControl IsTabStop="False" ItemsSource="{Binding Path=BranchCommands}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button Tag="{Binding}" Padding="3">
                <TextBlock Text="{Binding Path=DisplayValue}" />
            </Button>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

, ItemsControl.ItemsPanel, , ...

: Bea, Dr WPF.

+9

( ), ...

" =" ", , , : - ItemsControl. ControlTemplate ItemsControl, ControlTemplate StackPanel =" ".

, !

Edit:

, Bea /!

http://bea.stollnitz.com/blog/?p=10

+3

All Articles