2012-10-22 52 views
1

當用戶在我的應用程序中移動頁面時,簡單的動畫應該在移動之前淡出項目,但它不能正常工作並立即轉移。後退鍵不等待動畫

代碼:

 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)); 
      }; 
     } 

現在,這是不行的,它可以追溯到直的MainPage走,沒有任何人有線索?

回答

3

嘗試添加e.Cancel以停止自動處理上一頁,因爲您已經告訴它應該去哪個頁面。

void OnBackKeyPressed(object sender, CancelEventArgs e) 
{ 
    e.Cancel = true; 

    foreach (var control in ContentPanel.Children) 
      MainPage.FadeOutObject(control); 

    //...rest of your code 
}