When the user shift pages in my application, simple animation should fade out items before shifting, but it’s not working and going for the shift immediately.
Code:
public PageClass()
{
BackKeyPress += OnBackKeyPressed;
}
void OnBackKeyPressed(object sender, CancelEventArgs e)
{
foreach (var control in ContentPanel.Children)
MainPage.FadeOutObject(control);
var translation = new TranslateTransform();
PageTitle.RenderTransform = translation;
var s = new Storyboard();
Storyboard.SetTarget(s, translation);
Storyboard.SetTargetProperty(s, new PropertyPath(TranslateTransform.YProperty));
s.Children.Add(
new DoubleAnimation()
{
From = -300,
To = 0,
Duration = new Duration(TimeSpan.FromSeconds(2.0)),
EasingFunction = new PowerEase { EasingMode = EasingMode.EaseInOut }
});
s.Begin();
s.Completed += (object sd, EventArgs ea) =>
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
};
}
Now, this does not work, it goes back to the MainPage straight away, does anyone have a clue?
Try adding
e.Cancelto stop the previous page from being handled automatically, since you’re already telling it which page it should go to.