I'm trying to animate a canvas by swiping using ´ManipulationDelta`. The problem is simple. when I run the app, the only time the manipulation event is not fired is at the first try. If I tap (or swipe) anywhere in the canvas once, then the second time it works until the application is restarted.
This is my XAML code:
<Canvas Name="rootCanvas" Style="{StaticResource rootCanvas}" Hold="rootCanvas_Hold" ManipulationDelta="rootCanvas_ManipulationDelta" ManipulationCompleted="rootCanvas_ManipulationCompleted">
<Canvas.Resources>
<Storyboard x:Name="menuAnimation">
<DoubleAnimation Duration="0:0:0.2" To="0" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="rootAnimation" d:IsOptimized="True" />
</Storyboard>
</Canvas.Resources>
<Canvas Name="rootAnimation">
<Grid x:Name="rootContainer" DataContext="{Binding}" Style="{StaticResource rootContainer}">
...
</grid>
</Canvas>
</Canvas>
And this is my code in C#
private void rootCanvas_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
if (e.DeltaManipulation.Translation.X > 25 && !menu.IsMenuOpen())
{
MoveViewWindow(150);
hintActive = false;
menu.SetMenuOpen();
return;
}
else if (e.DeltaManipulation.Translation.X < (-25) && menu.IsMenuOpen())
{
MoveViewWindow(0);
hintActive = false;
menu.SetMenuClosed();
return;
}
}
private void rootCanvas_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
if (!menu.IsMenuOpen())
{
hintActive = true;
MoveViewWindow(25);
}
return;
}
I have a rootCanvas_ManipulationCompleted
where the breakpoint gets hit even if the ManipulationDelta and Hold breakpoints aren't.
Any ideas?
Try the command:
rootCanvas.Focus();
This will set focus to the canvas you are hitting, just pop this event in the load method of the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With