单行水平滚动/可滑动GridView [英] Single Row Horizontally Scrolling/Swipeable GridView

查看:90
本文介绍了单行水平滚动/可滑动GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个单行GridView,可以同时使用鼠标和触摸滑动来水平滚动. GridView将通过绑定显示图像,以便从图像数组中选择单个图像.

I wanted a single-row GridView that can be scrolled horizontally both with mouse and touch swipe. The GridView is to present images through binding so that a single image will be selected from an array of images.

除了水平滚动条不起作用外,其他所有东西(绑定,图像选择等)都可以正常工作. XAML代码如下所示.

Everything works fine (binding, image selection, etc.) except that the horizontal scroll doesn't work. The XAML code is shown below.

我想念什么?

<GridView x:Name="IconGridView"
    Grid.Row="0"
    Margin="8,12"
    DataContext="{x:Bind IconManagerObj}"
    DoubleTapped="{x:Bind IconGridView_DoubleTapped}"
    IsItemClickEnabled="True"
    IsSwipeEnabled="True"
    ItemsSource="{Binding Path=IconImageInfo}"
    ScrollViewer.HorizontalScrollBarVisibility="Auto"
    ScrollViewer.HorizontalScrollMode="Enabled"
    ScrollViewer.VerticalScrollMode="Disabled"
    SelectionMode="Single"
    Tapped="{x:Bind IconGridView_Tapped}">

    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>

    <GridView.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="4,8"
            HorizontalAlignment="Center"
            BorderBrush="{ThemeResource SubtleBlueBrush}"
            BorderThickness="1">
               <Image Width="150" Source="{Binding IconImage}Stretch="Uniform"/>
           </StackPanel>
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>

推荐答案

您一切正常,但ItemsWrapGrid的 Orientation 必须为 Vertical ,以便具有水平ScrollViewer.

You have everything right but the Orientation for the ItemsWrapGrid must be Vertical in order to have an Horizontal ScrollViewer.

此处的文档 https://msdn. microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.itemswrapgrid.aspx 解释说:

当值为垂直"时,网格将在顶部到底部的列中添加项目,然后从左到右环绕.项目列会水平滚动或平移.

When the value is Vertical, the grid adds items in columns from top to bottom, then wraps from left to right. Columns of items scroll or pan horizontally.

这篇关于单行水平滚动/可滑动GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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