【问题标题】:Manipulation on Pivot in Windows Phone 8.1在 Windows Phone 8.1 中操作 Pivot
【发布时间】:2014-07-25 11:09:03
【问题描述】:

我有一个带有 2 个 PivotItems 的 Pivot。我正在尝试检测用户是向左还是向右滑动。我想我可以通过检查 ManipulationStarted 和 ManipulationCompleted 点之间的差异来检测到这一点。但无论我做什么,这些事件都不会被触发。

<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>

我也尝试过检测指针。 PointerEntered 事件确实会被触发,但 PointerExited/PointerReleased/PointerCanceled 不会...

【问题讨论】:

  • 你想做什么?

标签: c# windows-phone-8 pivot windows-phone-8.1


【解决方案1】:

很抱歉回复晚了。

你是对的 WP 8.X 的一些系统控件,拦截触摸事件。原因是系统控件的性能优化和用户体验的改善。 但是操作系统提供了一种通过 FrameworkElement 的UseOptimizedManipulationRouting 属性来控制这种行为的方法。

【讨论】:

    【解决方案2】:

    喜欢yasen had said - Pivot 拦截触摸事件。我认为其中一种解决方案可能是禁用您的 Pivot 并使用 Grid 的 ManipulationCompleted 事件(在这种情况下,您将不得不手动更改 PivotItems):

    在 XAML 中:

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

    在后面的代码中:

    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;
    }
    

    【讨论】:

    • 这是一个很好的解决方案,尽管 Pivot 不会随着实时滑动而移动。我知道这可以通过使用 ManipulationDelta 来解决。我只是想知道是否有一个简单的解决方案。因为没有,我想我会改变我的逻辑,所以我可以使用三个数据透视项(所以我可以使用 SelectionChanged)。还是谢谢!
    【解决方案3】:

    您所说的事件是由 Pivot 本身处理的,因此您自己捕捉它们可能会很棘手。

    也许您可以使用 Pivot 的 SelectionChanged 事件?或者可能是 Loading/Loaded/Unloading/UnloadedPivotItem 事件?

    【讨论】:

    • 我认为最好的方法是找到一种方法来处理 3 个数据透视项,这样我就可以使用 SelectionChanged 事件..
    • @PhilippeMaes 请问你想达到什么目标?当你检测到滑动时你想做什么?
    • 我正在实现通过滑动专辑封面(位于轴中)来跳到下一首和上一首歌曲的功能。
    • @PhilippeMaes 您想在用户滑动时更改 PivotItem 吗?如果没有,那不是一个好主意。这将是糟糕的用户体验,因为在 Pivot 上滑动的人希望更改 PivotItem。
    • 当用户滑动时 PivotItem 会改变 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多