WPF Page 界面跳转简单框架和DoubleAnimation动画跳转界面

界面显示

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

CSDN下载   https://download.csdn.net/download/sun_zeliang/10636546  需两积分

百度云下载   链接:https://pan.baidu.com/s/1OJ5BMDDUi8r8ciEAijQdOA 密码:qmia  不需要积分

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值