2011-03-30 91 views
1

在返回鍵被按下之前,我想添加一個動畫。現在我只需要在後退鍵的覆蓋方法中播放動畫。它並不完全播放動畫。有沒有辦法取消後退事件並將其添加到動畫完成事件?或者什麼是實現這一目標的最佳方式?按下後退鍵時的動畫

回答

7

試試這個:

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) 
{ 
    if(NavigationService.CanGoBack()) { 
    // Cancel the navigation 
    e.Cancel = true; 

    //Create the storyboard 
    Storyboard anim = new MyCoolAnimation(); 

    // Hook an on complete handler 
    EventHandler handler = null; 
    handler = (s, e) => { 
     // Navigate backward 
     NavigationService.GoBack(); 

     anim.Completed -= handler; 
    }; 
    anim.Completed += handler; 

    // Start the storyboard 
    anim.Begin(); 
    } 
} 
+0

將這個還努力關閉應用程序的最後一頁,因此關閉它? – 2011-03-31 08:31:38

+0

@Matt Lacey:我不這麼認爲;我認爲'NavigationService.CanGoBack()'返回'false'爲最後一頁(當應用程序啓動時的第一頁) – Praetorian 2011-03-31 12:15:28

相關問題