2011-12-24 16 views
0

WP 7.5應用程序。我有兩個Storyboard動畫 - 一個在圖像上,另一個在文本上。使用Obscure和UnObscure ...我正在做對嗎?

問題1:當我移動到下一頁並返回時,圖像和文字閃爍。

解決方法1:所以我添加OnNavigateFrom和明確地停止動畫,還參與了動畫的任何屬性重置爲0

Issue2:現在說在屏幕進入鎖定模式,當我解鎖,因爲我在OnNavigatedFrom中將我的一個元素的不透明度設置爲0,所以元素被隱藏,實際上應該是可見的,直到用戶移動到下一頁。

解決方案2:我在代碼中處理了如下所示的遮罩和未遮罩的處理程序,並添加了一個標記以查看應用程序是否會遮擋模式,請勿停止動畫或重置屬性。

public class Page2 :PhoneApplicationPage 
    { 
     private bool _isObscured = false; 
     public Page2() 
     { 
      (Application.Current as App).RootFrame.Obscured += OnObscured; 
      (Application.Current as App).RootFrame.Unobscured += OnUnobscured; 
      InitializeComponent(); 
     } 

     protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) 
     { 
      //Stop animations and reset properties only if not going to obscure mode. 
      if (!_isObscured) 
      { 
       //stop animaiton 
       Storyboard1.Stop(); 
       Storyboard2.Stop(); 
       //Reset all transform properties to 0 
       Text1.Opacity = 0; 
       Image1.RenderTransform.SetValue(CompositeTransform.ScaleXProperty, 0.0); 
       Image1.RenderTransform.SetValue(CompositeTransform.ScaleYProperty, 0.0); 
      } 
      base.OnNavigatedFrom(e); 
     } 

     void OnObscured(object sender, ObscuredEventArgs e) 
     { 
      Storyboard1.Pause(); 
      Storyboard2.Pause(); 
      _isObscured = true; 
     } 

     void OnUnobscured(object sender, EventArgs e) 
     { 
      Storyboard1.Resume(); 
      Storyboard2.Resume(); 
      _isObscured = true; 
     } 
    } 

問題:這是要走的路corret還是有更好的辦法?這樣做會不會有任何認證問題?

任何幫助真的很感激。

回答

0

更簡單的方法是添加IsLeave布爾屬性,並在調用NavigateTo方法的點擊事件中將其設置爲true。另外,也停止使用相同功能的動畫。

比你可以肯定的是,當你回來時,IsLeave屬性說你執行動畫或不。

private bool IsLeave = false;

OnNavigatedTo() 
{ 
     if (IsLeave) 
     { 
      //We come back. Reset animations 
      IsLeave = false; 
     } 
} 

ClickEvent() 
{ 
     IsLeave = true; 
     //Permorm all you need with animations. We leave this page 
     NavigationService.NavigateTo() 
} 
+0

我完全不明白嗎?當屏幕鎖定被遮擋時,這會如何提供幫助? – oms 2011-12-24 17:33:58

+0

在這種情況下,當屏幕被鎖定時,OnNavigatedFrom方法中不再有不透明度的變化。所以,當你回來時 - 所有元素仍然可見。並且您的Solution1不生成問題2,我認爲 – Ku6opr 2011-12-24 18:58:35

+0

我明白了。我將不得不測試一下。另外我的NavigationService.NavigateTo()在一個customControl中,它通過MouseLeftButtonDown處理我的圖像的導航。我會嘗試更新。謝謝。 – oms 2011-12-24 20:24:03