wpf 带有水平项目的 ListView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32895171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:27:05  来源:igfitidea点击:

ListView with horizontal items

wpfxamllistviewwin-universal-appuwp

提问by SuperJMN

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).

我来自 WPF,我不知道是否可以制作一个 ListView 来水平分布项目,以及鼠标滚轮(鼠标设备)和滑动(触摸设备)等所有附加功能。

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>

回答by SuperJMN

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>

回答by Khawaja Asim

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>

回答by moneeb

<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>