WPF Page 介面跳轉簡單框架和DoubleAnimation動畫跳轉介面
阿新 • • 發佈:2019-02-08
介面顯示
public enum PageType { Index, Error, Copy, Wait, None } public class UIController { public delegate void ChangeFrmMainDelegate(object content); public static event ChangeFrmMainDelegate ChangeFrmMainEvent; public static void PageShow(PageType page, string error = null) { switch (page) { case PageType.Index: ChangeFrmMainEvent.Invoke(new Index()); break; case PageType.Copy: ChangeFrmMainEvent.Invoke(new Wpf_Page_Copy()); break; case PageType.Error: ChangeFrmMainEvent.Invoke(new Wpf_Page_Error(error)); break; case PageType.Wait: ChangeFrmMainEvent.Invoke(new Wpf_Page_Wait()); break; case PageType.None: break; default: break; } } }
延時跳轉
private DispatcherTimer dispatcherTimer = new DispatcherTimer(); private void Page_Loaded(object sender, RoutedEventArgs e) { //定時查詢-定時器 dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 2); dispatcherTimer.Start(); } /// <summary> /// 定時器回撥函式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dispatcherTimer_Tick(object sender, EventArgs e) { dispatcherTimer.Stop(); UIController.PageShow(PageType.Wait); dispatcherTimer = null; GC.Collect(); }
DoubleAnimation 漸隱漸現動畫 (如果不需要動畫,只想用這個介面顯示的框架,只需要把ChangeFrmMain方法裡面的程式碼 換成 this.frmMain.Navigate(content); 就可以了 frmMain 是一個Frame控制元件
private void ChangeFrmMain(object content) { this.content = content; try { if (Content != null) { this.IsHitTestVisible = false; DoubleAnimation da = new DoubleAnimation(0.3d, new Duration(TimeSpan.FromMilliseconds(300))); da.Completed += FadeOutCompleted; this.BeginAnimation(OpacityProperty, da); } } catch { } } private void FadeOutCompleted(object sender, EventArgs e) { (sender as AnimationClock).Completed -= FadeOutCompleted; this.IsHitTestVisible = true; Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (ThreadStart)delegate () { DoubleAnimation da = new DoubleAnimation(1.0d, new Duration(TimeSpan.FromMilliseconds(200))); this.BeginAnimation(OpacityProperty, da); }); this.frmMain.Navigate(content); }
百度雲下載 連結:https://pan.baidu.com/s/1OJ5BMDDUi8r8ciEAijQdOA 密碼:qmia 不需要積分