具有水平项目流的 Windows 8 ListView [英] Windows 8 ListView with horizontal item flow

查看:22
本文介绍了具有水平项目流的 Windows 8 ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使 Windows 8 ListView 中的 ListItems 水平流动.默认行为是垂直的,但我想以水平流方式显示列表,以便它可以呈现为全景图.

How can i make the ListItems inside windows 8 ListView to flow horizontally. Default behavior is vertical, but i want to show the list in horizontal flow so it can render as panorama.

我尝试了支持水平布局的 GridView,但对项目高度有限制,无法显示大文本项目的完整项目内容.

I tried GridView which does support horizontal layout but there is a limitation on item height which does not show the complete item content for items with large text.

推荐答案

你可以这样使用 ListView:

You can use a ListView this way:

<ListView
    Height="500"
    VerticalAlignment="Center"
    ScrollViewer.HorizontalScrollBarVisibility="Auto"
    ScrollViewer.VerticalScrollBarVisibility="Disabled"
    ScrollViewer.HorizontalScrollMode="Enabled"
    ScrollViewer.VerticalScrollMode="Disabled"
    ScrollViewer.ZoomMode="Disabled"
    SelectionMode="None">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsStackPanel
                Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>

-- 这给它一个水平面板和用于水平滚动的右侧 ScrollBars.

-- that gives it a horizontal panel and the right ScrollBars for horizontal scrolling.

当您获得较大的项目时,ListView 和 GridView 都会导致问题.我认为默认情况下,项目的大小可能基于添加的第一个项目的大小.您可以手动设置该大小:

Both ListView and GridView can cause problems when you get larger items. I think by default the items might be sized based on the size of the first item added. You can set that size manually though:

<ListView.ItemContainerStyle>
    <Style
        TargetType="ListViewItem"><!-- note - for GridView you should specify GridViewItem, for ListBox - ListBoxItem, etc. -->
        <Setter
            Property="Height"
            Value="200" /> <!-- this is where you can specify the size of your ListView items -->
        <Setter
            Property="Width"
            Value="350" />
    </Style>
</ListView.ItemContainerStyle>

-- 请注意,所有项目的大小都必须相同.

-- note that all items need to be the same size.

--另请注意-我已更改此答案以将 StackPanel 替换为虚拟化的 ItemsStackPanel,因此它应该为您提供更好的性能和更低的内存使用量大型数据集,但 - 不要创建具有大型、可水平滚动列表的布局.在某些非常有限的场景中,它们可能是一个很好的解决方案,但在大多数情况下,它们会破坏许多良好的 UI 模式并使您的应用更难使用.

-- also note - I have changed this answer to replace a StackPanel with an ItemsStackPanel which is virtualized, so it should get you better performance and lower memory usage for large data sets, but PLEASE - don't create layouts with large, horizontally scrollable lists. They might be a good solution in some very limited scenarios, but in most cases they will break many good UI patterns and make your app harder to use.

这篇关于具有水平项目流的 Windows 8 ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆