コード例 #1
0
        /// <summary>
        /// 显示通知窗口
        /// </summary>
        /// <param name="_notificationWindow">要显示的通知窗口</param>
        private void OpenNotification(NotificationWindow _notificationWindow)
        {
            //让[任务栏进度条]闪烁
            AppManager.AppSystems.TaskbarSystem.SetProgressTwinkling(true);

            //获取这个窗口
            NotificationWindow self = _notificationWindow;

            //如果这个窗口不为null
            if (self != null)
            {
                self.UpdateLayout();

                //获取窗口的宽度
                //windowWidth = self.Width;

                //播放提示声
                AppManager.AppSystems.AudioSystem.PlayAudio(AudioType.Complete);

                //计算窗口多久消失
                showTime = AppManager.AppSystems.AudioSystem.CompleteAudioLength + 2f;

                /* 计算窗口出现的位置 */
                //获取工作区最右边的值
                double right = System.Windows.SystemParameters.WorkArea.Right;
                self.Top  = self.topFrom - self.ActualHeight;
                self.Left = right - self.ActualWidth - horizontalSpacing;

                /* 动画 */
                DoubleAnimation animation = new DoubleAnimation();

                //animationTime,用来设置动画的持续时间
                animation.Duration =
                    new Duration(TimeSpan.FromSeconds(animationTime));
                animation.From = windowWidth;
                //设定通知从右往左弹出

                /* 注意:这里的horizontalSpacing代表离屏幕右边的距离,
                 *      这个值越大,那么窗口离屏幕右边越远*/
                animation.To             = 0;
                animation.EasingFunction = new SineEase();
                //设定动画应用于窗体的Left属性
                self.NotificationGrid.BeginAnimation(Canvas.LeftProperty, animation);

                Task.Factory.StartNew(delegate
                {
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(showTime));
                    //Invoke到主进程中去执行
                    Invoke(self, delegate {
                        CloseNotification();//关闭通知窗口
                    });
                });
            }
        }
コード例 #2
0
        /// <summary>
        /// 显示一个通知窗口
        /// (显示一条通知)
        /// </summary>
        public void ShowNotification()
        {
            //new 一个通知窗口
            NotificationWindow notificationWindow = new NotificationWindow();

            //当窗口关闭时,触发什么方法?
            notificationWindow.Closed += NotificationWindow_Closed;

            //计算窗口的底部位置(窗口的底部在屏幕的什么位置?)
            notificationWindow.topFrom           = GetTopFrom();
            notificationWindow.horizontalSpacing = horizontalSpacing;

            //把窗口添加到列表中
            notificationWindows.Add(notificationWindow);

            //显示窗口
            notificationWindow.Show();
        }