Horizontal ListBox Elements

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

            <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 the layout behavior of the elements as follows: http://www.freeimagehosting.net/uploads/cf4f839d02.png]

As you can see, the second element is smaller and the VerticalLayout is not the top as I want.

Can someone help me?

+5
source share
1 answer

HorizontalAlignment and VerticalAlignment refer to how the StackPanel aligns in its parent container.

, ItemContainerStyle, VerticalAlignment Stretch ( ListBoxItem ListBox) VerticalContentAlignment to Top ( ListBoxItem ListBoxItem).

+5

All Articles