How do you do transition effects using the Frame control in WPF?

后端 未结 4 745
情深已故
情深已故 2020-12-01 01:52

I thought this would be easy but I guess not.

I have 2 pages that load in my frame control. I want to be able to either have a nice slide effect from one page to the

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 02:11

    My answer is the improved version of the answer given by serge_gebunko.
    It gives you the Sliding left and right effect.

    XAML

    ...
    
    ...
    

    C#

     private void MainFrame_OnNavigating(object sender, NavigatingCancelEventArgs e) {
                    var ta = new ThicknessAnimation();
                    ta.Duration = TimeSpan.FromSeconds(0.3);
                    ta.DecelerationRatio = 0.7;
                    ta.To = new Thickness(0 , 0 , 0 , 0);
                    if (e.NavigationMode == NavigationMode.New) {         
                        ta.From = new Thickness(500, 0, 0, 0);                                                  
                    }
                    else if (e.NavigationMode == NavigationMode.Back) {                
                        ta.From = new Thickness(0 , 0 , 500 , 0);                                               
                    }
                     (e.Content as Page).BeginAnimation(MarginProperty , ta);
                }
    

提交回复
热议问题