在Windows Phone 8.1中对数据透视进行操作 [英] Manipulation on Pivot in Windows Phone 8.1
问题描述
我有一个带有2个PivotItems的Pivot.我正在尝试检测用户是向左还是向右滑动.我以为可以通过检查ManipulationStarted和ManipulationCompleted点之间的差异来检测到这一点.但是无论我做什么,这些事件都不会触发.
I have a Pivot with 2 PivotItems. 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. 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>
我也尝试过检测Pointer.虽然会触发PointerEntered事件,但不会触发PointerExited/PointerReleased/PointerCanceled ...
I also tried with detecting Pointer. The PointerEntered event does get fired, but the PointerExited/PointerReleased/PointerCanceled don't...
推荐答案
像 yasen所说的-枢轴拦截了触摸事件.我认为解决方案之一可能是禁用您的Pivot并利用Grid的ManipulationCompleted
事件(在女巫中,您将不得不手动更改PivotItems):
Like yasen had said - Pivot intercepts touch events. 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):
在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;
}
这篇关于在Windows Phone 8.1中对数据透视进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!