Reputation: 510
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>
I also tried with detecting Pointer. The PointerEntered event does get fired, but the PointerExited/PointerReleased/PointerCanceled don't...
Upvotes: 0
Views: 4033
Reputation: 5833
I'm sorry for the late answer.
You are right some system controls of WP 8.X, intercept touch events. 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.
Upvotes: 0
Reputation: 29792
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):
In 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;
}
Upvotes: 3
Reputation: 3580
The events you're talking about are handled by the Pivot itself, so it might be tricky to catch them yourself.
Maybe you can use the Pivot's SelectionChanged event? Or maybe the Loading/Loaded/Unloading/UnloadedPivotItem events?
Upvotes: 2