如何让水平列表框在 WP7 中水平滚动? [英] How do I get a Horizontal ListBox to scroll horizontally in WP7?

查看:47
本文介绍了如何让水平列表框在 WP7 中水平滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用下面的代码在 WP7 silverlight 中创建一个水平列表框.项目水平显示,但滚动仍然是垂直的.

I'm attempting to use the code below to make a horizontal listbox in WP7 silverlight. The items appear horizontally but the scrolling is still vertical.

我在 wpf 中做错了什么吗?这是 WP7 特定的错误吗?.

Am I doing something wrong in wpf? Is this a WP7 specific bug?.

    <Style TargetType="ListBox" x:Name="HorizontalListBox">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal" 
                                            IsItemsHost="True" 
                                            CanHorizontallyScroll="True" 
                                            CanVerticallyScroll="False"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

我遗漏了两个似乎有很大不同的属性.(解决方案来自 Mick N 接受的答案中的第二个链接.)

I was missing two properties that appear to make a great deal of difference. (The solution came from the second link in the accepted answer by Mick N.)

    <Style TargetType="ListBox" x:Name="HorizontalListBox">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" CanHorizontallyScroll="True" CanVerticallyScroll="False"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
    </Style>

推荐答案

这里提出了两种解决方案,您可以尝试一下.

Two solutions proposed here you can try out.

水平列表框?

如何编写控件类似于ListBox,但从左向右滑动而不是向上和向下滑动

这篇关于如何让水平列表框在 WP7 中水平滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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