Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal ListBox items vertical layout

Tags:

I have horizontal ListBox. Here is code for it (removed some irrelevant):

            <ListBox Grid.Row="1"
                     ItemContainerStyle="{StaticResource ListBoxUnselectableItemStyle}"
                     ItemsSource="{Binding ...}"
                     BorderThickness="0"
                     Background="{x:Null}"
                     ScrollViewer.CanContentScroll="False">

                <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"
                                        VerticalAlignment="Top"
                                        HorizontalAlignment="Center"
                                        Background="Red"/>
                        </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>




And I get items' layout behavior like this: http://www.freeimagehosting.net/uploads/cf4f839d02.png]

As you can see, second item is smaller, and VerticalLayout is not Top as I want.

Can anybody help me?

like image 546
levanovd Avatar asked Nov 12 '09 21:11

levanovd


1 Answers

HorizontalAlignment and VerticalAlignment refer to how the StackPanel is aligned within its parent container.

You probably need to be looking at ItemContainerStyle, where you would set VerticalAlignment to Stretch (so that the ListBoxItem occupies the full height of the ListBox), and VerticalContentAlignment to Top (so that the content of the ListBoxItem is aligned to the top of the ListBoxItem).

like image 59
itowlson Avatar answered Oct 12 '22 23:10

itowlson