KillaKem
KillaKem

Reputation: 1025

How to Navigate to another Page After running an Animation

Basically I have a couple of buttons on a page, when a user clicks one of the buttons the application has to run an animation then navigate to a second page with the name of the button stored in the query string

 private void Button1_Click(object sender, RoutedEventArgs e)
        {
            myAnimation.Begin();
            myAnimation.Completed += new EventHandler(myAnimation_Completed);

        }

        void myAnimation_Completed(object sender, EventArgs e)
        {
             //If Button1 was clicked
            NavigationService.Navigate(new Uri("/nextPage.xaml?id=Button1",UriKind.Relative));

             //If Button2 was clicked
            NavigationService.Navigate(new Uri("/nextPage.xaml?id=Button2",UriKind.Relative));

             //etc
        }

I don't know what condition I can use for the IF statements.

EDIT: Managed to solve the navigation problem by changing the event statement to

myAnimation.Completed += new EventHandler((a,b) => MyAnimation_complete(sender, e)); 

but now am having trouble navigating back, when I click the back button from the second page I go to the first page but I find no controls there.It may also be helpful to note the "MyAnimation" is just a transition animation.

Upvotes: 1

Views: 302

Answers (3)

S3ddi9
S3ddi9

Reputation: 2151

why don't use lambda expressions

private void Button1_Click(object sender, RoutedEventArgs e)
    {
        myAnimation.Begin();
        myAnimation.Completed += (s,ev)=>
          {
           NavigationService.Navigate(new Uri("/nextPage.xaml?id=Button1",UriKind.Relative));
          };

    }

samething for Button2

Upvotes: 1

voluminat0
voluminat0

Reputation: 906

You could try:

myAnimation.Completed += new EventHandler((sender, e) => MyAnimation_complete(sender, e);

In this way, you can get your infromation from your e variable, and handle your buttons this way.

Upvotes: 2

Krzysztof Cieslak
Krzysztof Cieslak

Reputation: 1735

Just create bool variable which is set to true if Button 1 is clicked and to false when button 2 (or some int if You have more buttons)

Upvotes: 1

Related Questions