WPF ListBox that lays out its items horizontally

后端 未结 2 1300
栀梦
栀梦 2021-01-31 13:45

I\'m trying to write a WPF application for displaying images from a selection. I want to display all of the available images in a banner along the top of the window, and display

相关标签:
2条回答
  • 2021-01-31 14:40

    The default ItemsPanel for the ListBox control is a VirtualizingStackPanel, so if you want the normal, default experience for the control but just have it laid out horizontally, you should specify this (and change the orientation).

    Example:

    <ListBox>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
    
    0 讨论(0)
  • 2021-01-31 14:41

    WrapPanel

     <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel IsItemsHost="True" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBoxItem>listbox item 1</ListBoxItem>
        <ListBoxItem>listbox item 2</ListBoxItem>
        <ListBoxItem>listbox item 3</ListBoxItem>
        <ListBoxItem>listbox item 4</ListBoxItem>
        <ListBoxItem>listbox item 5</ListBoxItem>
    </ListBox>
    

    WPF Tutorial

    0 讨论(0)
提交回复
热议问题