如何允许在ListView/GridView项目控件中进行操作,同时允许对ListView/GridView进行滚动和交叉滑动操作? [英] How to allow manipulations within ListView/GridView Item controls while allowing scroll and cross-slide manipulations on the ListView/GridView?

查看:35
本文介绍了如何允许在ListView/GridView项目控件中进行操作,同时允许对ListView/GridView进行滚动和交叉滑动操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体地说,我有一个自定义用户控件,该控件接收操作事件以滚动自定义DirectX控件.此控件以及其他类似控件都是GridView中的项目.我希望GridView能够通过默认的TranslateRailsX操作水平滚动,而控件应该能够接收TranslateRailsY操作事件.

Specifically, I have a custom user control that receives manipulation events to scroll a custom DirectX control. This control, and others like it, are items in a GridView. I want the GridView to be able to scroll horizontally through the default TranslateRailsX manipulation, while the controls should be able to receive TranslateRailsY manipulation events.

到目前为止,在我的实验中,通过将控件的操作模式设置为System,可以使GridView滚动条正常工作,但是控件不会收到任何操作事件.通过将控件的操作模式设置为全部","TranslateY"或"TranslateRailsY",我可以使我的自定义控件接收操作事件,但是GridView触摸滚动将不起作用.

In my experiments so far, by setting the controls' manipulation mode to System, I can get the GridView scroll to work, but the controls will not receive any manipulation events. By setting the controls' manipulation mode to All, or TranslateY, or TranslateRailsY, I can get my custom control to receive the manipulation events, but the GridView touch scroll will not work.

如何允许这两种操作?

推荐答案

8.0无法完成(对于8.1滚动到EDIT).您将需要实现自己的ScrollViewer以在GridView模板中使用,或者在GridView上放置一个层,并在我

It can't be done with 8.0 (for 8.1 scroll to EDIT). You would need to implement your own ScrollViewer to use in the GridView template or put a layer on top of the GridView and relay all input calls as I suggested before. Actually, perhaps implementing your own version of ScrollViewer wouldn't be that hard (a Canvas control with one child that calls Canvas.SetLeft on its child item on manipulation events).

我可能对您有用的一个新想法是,将另一个ScrollViewer放置在DirectX控件的前面,并像使用操作事件一样使用其ViewChanged事件-选中此项:

One new idea I have that might work for you is to put another ScrollViewer in front of your DirectX control and use its ViewChanged events as you would use the manipulation events - check this:

XAML

<Page
    x:Class="App84.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App84"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid
        Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <GridView>
            <Grid
                Width="300"
                Height="300">
                <Rectangle
                    x:Name="DirectXControlPlaceholder"
                    Width="300"
                    Height="300"
                    Fill="Yellow" />
                <ScrollViewer
                    x:Name="ManipulationCaptureScrollViewer"
                    Style="{StaticResource VerticalScrollViewerStyle}"
                    VerticalScrollBarVisibility="Hidden"
                    ViewChanged="ScrollViewer_OnViewChanged">
                    <Rectangle
                        Width="200"
                        Height="10000"
                        Fill="Transparent"/>
                </ScrollViewer>
                <TextBlock
                    x:Name="OffsetTextBlock"
                    Foreground="Black"
                    FontSize="24"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    />
            </Grid>
            <Rectangle
                Width="300"
                Height="300"
                Fill="GreenYellow" />
            <Rectangle
                Width="300"
                Height="300"
                Fill="LimeGreen" />
            <Rectangle
                Width="300"
                Height="300"
                Fill="Red" />
            <Rectangle
                Width="300"
                Height="300"
                Fill="OrangeRed" />
            <Rectangle
                Width="300"
                Height="300"
                Fill="DarkOrange" />
            <Rectangle
                Width="300"
                Height="300"
                Fill="Orange" />
        </GridView>
    </Grid>
</Page>

背后的代码

using Windows.UI.Xaml.Controls;

namespace App84
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void ScrollViewer_OnViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            OffsetTextBlock.Text =
                ManipulationCaptureScrollViewer.VerticalOffset.ToString();
        }
    }
}

编辑*

在Windows 8.1中,您还会获得 ManipulationModes.System ,它与其他模式(虽然不支持缩放和旋转)相结合,应该可以让您在 ScrollViewer 内部进行操作.然后,您可以调用 <代码如果您希望其父元素 ScrollViewers 停止处理平移和缩放操作,请在该操作元素上> CancelDirectManipulations() .

Also with Windows 8.1 you get ManipulationModes.System which combined with other modes (scale and rotate are not supported though) should allow you to handle manipulations inside of a ScrollViewer. Then you can call CancelDirectManipulations() on the manipulated element once you want its parent ScrollViewers to stop processing manipulations for pan&zoom.

这篇关于如何允许在ListView/GridView项目控件中进行操作,同时允许对ListView/GridView进行滚动和交叉滑动操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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