滑动视图时,翻转视图不起作用,我正在使用以下代码方案将ManipulationMode作为All处理为子级

时间:2018-08-03 05:00:58

标签: uwp uwp-xaml

我在FlipView中尝试了以下方法,将内部滚动视图的子元素的ManipulationMode处理为All。但是我面临的问题是,使用触摸滑动导航下一页时不会使用触摸,在鼠标情况下以及在操作模式下作为系统正常工作。我用下面的代码。

问题:触摸下一页的FlipView无法正常工作。

对于项目的子级StackPanels和VisualContainer ManipulationMode作为系统,它工作正常。但是在子项的子级StackPanels和VisualContainer ManipulationMode中都不能正常工作。

注意:我必须将子堆栈面板(Items,VisualContainer)ManipulationMode设置为ALL。 (本地:StackPanelExt是项)

在此附上示例代码段。

MainPage.xaml

<Page
x:Class="App4.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App4"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<FlipView>

    <Grid>
        <ScrollViewer x:Name="ScrollViewer1">
            <local:VisualContainer x:Name="VisualContainer1" Background="Red" HorizontalAlignment="Stretch">
                <local:StackPanelExt Background="Aquamarine" Height="100" />
                <local:StackPanelExt Background="Pink" Height="100" />
                <local:StackPanelExt Background="Aquamarine" Height="100" />
                <local:StackPanelExt Background="Pink" Height="100" />
                <local:StackPanelExt Background="Aquamarine" Height="100" />
                <local:StackPanelExt Background="Pink" Height="100" />
                <local:StackPanelExt Background="Aquamarine" Height="100" />
                <local:StackPanelExt Background="Pink" Height="100" />
                <local:StackPanelExt Background="Aquamarine" Height="100" />
                <local:StackPanelExt Background="Pink" Height="100" />
                <local:StackPanelExt Background="Aquamarine" Height="100" />
                <local:StackPanelExt Background="Pink" Height="100" />
            </local:VisualContainer>
        </ScrollViewer>
    </Grid>

    <Grid>
        <ScrollViewer x:Name="ScrollViewer2">
            <local:VisualContainer x:Name="VisualContainer2" Background="Red" HorizontalAlignment="Stretch">
                <local:StackPanelExt Background="AliceBlue"  Height="100" />
                <local:StackPanelExt Background="Red"  Height="100" />
                <local:StackPanelExt Background="AliceBlue"  Height="100" />
                <local:StackPanelExt Background="Red"  Height="100" />
                <local:StackPanelExt Background="AliceBlue"  Height="100" />
                <local:StackPanelExt Background="Red"  Height="100" />
                <local:StackPanelExt Background="AliceBlue"  Height="100" />
                <local:StackPanelExt Background="Red"  Height="100" />
                <local:StackPanelExt Background="AliceBlue"  Height="100" />
                <local:StackPanelExt Background="Red"  Height="100" />
                <local:StackPanelExt Background="AliceBlue"  Height="100" />
                <local:StackPanelExt Background="Red"  Height="100" />
            </local:VisualContainer>
        </ScrollViewer>
    </Grid>

    <Grid>
        <ScrollViewer x:Name="ScrollViewer3">
            <local:VisualContainer x:Name="VisualContainer3" Background="Red" HorizontalAlignment="Stretch">
                <local:StackPanelExt Background="Aqua"  Height="100" />
                <local:StackPanelExt Background="Yellow"  Height="100" />
                <local:StackPanelExt Background="Aqua"  Height="100" />
                <local:StackPanelExt Background="Yellow"  Height="100" />
                <local:StackPanelExt Background="Aqua"  Height="100" />
                <local:StackPanelExt Background="Yellow"  Height="100" />
                <local:StackPanelExt Background="Aqua"  Height="100" />
                <local:StackPanelExt Background="Yellow"  Height="100" />
                <local:StackPanelExt Background="Aqua"  Height="100" />
                <local:StackPanelExt Background="Yellow"  Height="100" />
                <local:StackPanelExt Background="Aqua"  Height="100" />
                <local:StackPanelExt Background="Yellow"  Height="100" />
            </local:VisualContainer>
        </ScrollViewer>
    </Grid>

</FlipView>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace App4
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {

        public MainPage()
        {
            this.InitializeComponent();

            this.VisualContainer1.ScrollViewerProperty = this.ScrollViewer1;
            this.VisualContainer2.ScrollViewerProperty = this.ScrollViewer2;
            this.VisualContainer3.ScrollViewerProperty = this.ScrollViewer3;
        }
    }

    public class VisualContainer : StackPanel
    {
        private bool isPointerPressed = false;

        public ScrollViewer ScrollViewerProperty
        {
            get;
            set;
        }

        public VisualContainer()
        {
            //this.ManipulationMode = ManipulationModes.System; // ----->>>> Working Fine 
            this.ManipulationMode = ManipulationModes.All;

            this.ManipulationDelta += VisualContainer_ManipulationDelta;
            this.PointerPressed += VisualContainer_PointerPressed;
        }

        private void VisualContainer_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            isPointerPressed = true;
        }

        private void VisualContainer_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            if (!e.IsInertial)
            {
                isPointerPressed = false;
            }
            else if (isPointerPressed)
            {
                e.Complete();
                return;
            }

            var offset = ScrollViewerProperty.VerticalOffset - e.Delta.Translation.Y;
            ScrollViewerProperty.ChangeView(0, offset, null, true);
        }
    }

    public class StackPanelExt : StackPanel
    {
        public StackPanelExt()
        {
            //this.ManipulationMode = ManipulationModes.System; // ----->>>> Working Fine 
            this.ManipulationMode = ManipulationModes.All;
        }
    }
}

注意:这里已附上样本,请点击以下链接下载 Sample

感谢进阶,

最好的问候,

Yuvaraj

0 个答案:

没有答案