简体   繁体   English

在Windows Phone 8.1中对数据透视进行操作

[英]Manipulation on Pivot in Windows Phone 8.1

I have a Pivot with 2 PivotItems. 我有一个带有2个PivotItems的Pivot。 I'm trying to detect whether the user swiped left or right. 我正在尝试检测用户是向左还是向右滑动。 I thought I could detect this by checking the difference between the ManipulationStarted and ManipulationCompleted point. 我以为可以通过检查ManipulationStarted和ManipulationCompleted点之间的差异来检测到这一点。 But whatever I do, those events won't get triggered. 但是无论我做什么,这些事件都不会触发。

<Pivot x:Name="albumart_pivot" Margin="0,-30,0,0" ManipulationStarted="ManipulationStartedEvent" ManipulationCompleted="ManipulationCompletedEvent" ManipulationMode="TranslateX">
    <PivotItem Margin="0">
        <Grid>
            <Rectangle Canvas.ZIndex="1" Fill="White" Opacity="0.1" Margin="20"/>
            <Image x:Name="albumart0" Stretch="UniformToFill" Canvas.ZIndex="1" Source="{Binding albumart}" Margin="20" Height="{Binding screenwidth}" Width="{Binding screenwidth}" ManipulationStarted="albumart_pivot_ManipulationStarted" ManipulationCompleted="albumart_pivot_ManipulationCompleted"/>
        </Grid>
    </PivotItem>
    <PivotItem Margin="0">
        <Grid>
            <Rectangle Canvas.ZIndex="1" Fill="White" Opacity="0.1" Margin="20"/>
            <Image x:Name="albumart1" Stretch="UniformToFill" Canvas.ZIndex="1" Source="{Binding albumart}" Margin="20" Height="{Binding screenwidth}" Width="{Binding screenwidth}" ManipulationStarted="albumart_pivot_ManipulationStarted" ManipulationCompleted="albumart_pivot_ManipulationCompleted"/>
        </Grid>
    </PivotItem>
</Pivot>

I also tried with detecting Pointer. 我也尝试过检测Pointer。 The PointerEntered event does get fired, but the PointerExited/PointerReleased/PointerCanceled don't... 不会触发PointerEntered事件,但不会触发PointerExited / PointerReleased / PointerCanceled ...

Like yasen had said - Pivot intercepts touch events. 就像yasen所说的那样 -枢轴截取触摸事件。 I think one of the solutions may be to disable your Pivot and make use of a Grid's ManipulationCompleted event (in witch you will have to change PivotItems manually): 我认为解决方案之一可能是禁用您的Pivot并利用Grid的ManipulationCompleted事件(在女巫中,您将不得不手动更改PivotItems):

In XAML: 在XAML中:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Pivot Name="myPivot">
        <PivotItem Header="One"/>
        <PivotItem Header="Two"/>
        <PivotItem Header="Three"/>                
    </Pivot>
</Grid>

In code behind: 在后面的代码中:

public MainPage()
{
    this.InitializeComponent();

    myPivot.IsHitTestVisible = false; // disable the Pivot 
    LayoutRoot.ManipulationMode = ManipulationModes.TranslateX;
    LayoutRoot.ManipulationCompleted+=LayoutRoot_ManipulationCompleted;
}

private void LayoutRoot_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
    var velocity = e.Velocities;
    if (velocity.Linear.X < 0) // swipe to the left
    {
        if (myPivot.SelectedIndex < myPivot.Items.Count - 1) myPivot.SelectedIndex++;
        else myPivot.SelectedIndex = 0;
    }
    else if (myPivot.SelectedIndex > 0) myPivot.SelectedIndex--; // to the right
    else myPivot.SelectedIndex = myPivot.Items.Count - 1;
}

The events you're talking about are handled by the Pivot itself, so it might be tricky to catch them yourself. 您正在谈论的事件是由Pivot本身处理的,因此自己捕获它们可能很棘手。

Maybe you can use the Pivot's SelectionChanged event? 也许您可以使用Pivot的SelectionChanged事件? Or maybe the Loading/Loaded/Unloading/UnloadedPivotItem events? 或者也许正在Loading / Loaded / Unloading / UnloadedPivotItem事件?

I'm sorry for the late answer. 对不起,我很抱歉。

You are right some system controls of WP 8.X, intercept touch events. 您正确的WP 8.X的某些系统控件,拦截触摸事件。 The cause is the performance optimization of the system controls and improvement of the user experience. 原因是系统控件的性能优化和用户体验的改善。 But the OS provides a way to control this behavior by the UseOptimizedManipulationRouting property of the FrameworkElement. 但是,OS通过FrameworkElement的UseOptimizedManipulationRouting属性提供了一种控制此行为的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM