最近做一個有頁面切換的吧..
我覺得這個功能是比較基礎的吧..
在網上百度了一下..
用NavigationWindow的比較好..
因為Demo中是帶了淡入淡出的頁面效果的..
我就想研究一下這個效果是怎么實現的..
發現找不到..
1 public partial class MainWindow : NavigationWindow 2 { 3 public MainWindow() 4 { 5 InitializeComponent(); 6 } 7 private void NavigationWindow_Navigating(object sender, NavigatingCancelEventArgs e) 8 { 9 if (Content != null && !_allowDirectNavigation) 10 { 11 e.Cancel = true; 12 _navArgs = e; 13 this.IsHitTestVisible = false; 14 DoubleAnimation da = new DoubleAnimation(0.3d, new Duration(TimeSpan.FromMilliseconds(100))); 15 da.Completed += FadeOutCompleted; 16 this.BeginAnimation(OpacityProperty, da); 17 } 18 _allowDirectNavigation = false; 19 } 20 21 private void FadeOutCompleted(object sender, EventArgs e) 22 { 23 (sender as AnimationClock).Completed -= FadeOutCompleted; 24 25 this.IsHitTestVisible = true; 26 27 _allowDirectNavigation = true; 28 switch (_navArgs.NavigationMode) 29 { 30 case NavigationMode.New: 31 if (_navArgs.Uri == null) 32 { 33 NavigationService.Navigate(_navArgs.Content); 34 } 35 else 36 { 37 NavigationService.Navigate(_navArgs.Uri); 38 } 39 break; 40 case NavigationMode.Back: 41 NavigationService.GoBack(); 42 break; 43 44 case NavigationMode.Forward: 45 NavigationService.GoForward(); 46 break; 47 case NavigationMode.Refresh: 48 NavigationService.Refresh(); 49 break; 50 } 51 52 Dispatcher.BeginInvoke(DispatcherPriority.Loaded, 53 (ThreadStart)delegate() 54 { 55 DoubleAnimation da = new DoubleAnimation(1.0d, new Duration(TimeSpan.FromMilliseconds(200))); 56 this.BeginAnimation(OpacityProperty, da); 57 }); 58 } 59 60 private bool _allowDirectNavigation = false; 61 private NavigatingCancelEventArgs _navArgs = null; 62 }