简体   繁体   中英

ListView with horizontal items

I come from WPF and I don't know if it's possible to make a ListView to distribute items horizontally, with all the extras like mouse-wheel scrolling (mouse devices) and swiping (touch devices).

I've tried this, but it doesn't behave like the vertical one. Example: I cannot scroll with the mouse-wheel.

<ListView ScrollViewer.VerticalScrollBarVisibility="Disabled"  ScrollViewer.HorizontalScrollBarVisibility="Auto" ItemsSource="{Binding Collection}" >
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"></StackPanel>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

OK, I found a way to make it work!

This is what I have. I don't know if it's configured fine, suggestions?

<ListView ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto"
    ScrollViewer.HorizontalScrollMode="Enabled"                  
    ScrollViewer.VerticalScrollMode="Disabled"
    ItemsSource="{Binding Collection}">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Background="Transparent" Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

This is more simple, maybe could help:

 <ListView>
     <ListView.ItemsPanel>
          <ItemsPanelTemplate>
              <StackPanel Orientation="Horizontal" />
          </ItemsPanelTemplate>
     </ListView.ItemsPanel>
     <ListView.ItemTemplate>
          <DataTemplate>
             <StackPanel Orientation="Horizontal" />
          </DataTemplate>
     </ListView.ItemTemplate>
 </ListView>
<ListBox Height="50" VerticalAlignment="Top">
 <ListBox.ItemsPanel>
      <ItemsPanelTemplate>
          <VirtualizingStackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBoxItem Content="aaaaaaaaaaa"/>
        <ListBoxItem Content="aaaaaaaaaaa"/>
        <ListBoxItem Content="aaaaaaaaaaa"/>
        <ListBoxItem Content="aaaaaaaaaaa"/>
        <ListBoxItem Content="aaaaaaaaaaa"/>
</ListBox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM