示例#1
0
        public void Show(object content, string areaName = "", TimeSpan?expirationTime = null, Action onClick = null,
                         Action onClose = null)
        {
            if (!_dispatcher.CheckAccess())
            {
                _dispatcher.BeginInvoke(
                    new Action(() => Show(content, areaName, expirationTime, onClick, onClose)));
                return;
            }

            if (expirationTime == null)
            {
                expirationTime = TimeSpan.FromSeconds(5);
            }

            if (areaName == string.Empty && _window == null)
            {
                var workArea = SystemParameters.WorkArea;

                _window = new NotificationsOverlayWindow
                {
                    Left   = workArea.Left,
                    Top    = workArea.Top,
                    Width  = workArea.Width,
                    Height = workArea.Height
                };

                _window.Show();
            }

            foreach (var area in Areas.Where(a => a.Name == areaName))
            {
                area.Show(content, (TimeSpan)expirationTime, onClick, onClose);
            }
        }
        public void Show(FrameworkElement content, string areaName = "", TimeSpan?expirationTime = null, Action onClick = null, Action onClose = null, Window parent = null)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (!_dispatcher.CheckAccess())
            {
                _dispatcher.BeginInvoke(new Action(() => Show(content, areaName, expirationTime, onClick, onClose)));
                return;
            }

            if (expirationTime == null)
            {
                expirationTime = TimeSpan.FromSeconds(5);
            }

            if (areaName == string.Empty && _window == null)
            {
                _window = new NotificationsOverlayWindow
                {
                    Owner  = parent ?? Application.Current.MainWindow,
                    Width  = content.Width,
                    Height = content.Height,
                };

                _window.Left = SystemParameters.FullPrimaryScreenWidth - _window.Width;
                _window.Top  = SystemParameters.FullPrimaryScreenHeight - _window.Height;

                _window.Show();
            }
            else
            {
                _window.Height = _window.Height + content.Height;
                _window.Top    = SystemParameters.FullPrimaryScreenHeight - _window.Height;
            }

            foreach (var area in Areas.Where(a => a.Name == areaName))
            {
                area.Show(content, (TimeSpan)expirationTime, onClick, onClose);
            }
        }