示例#1
0
        private async Task ShowMessageAsync()
        {
            Console.WriteLine($@"ShowMessageAsync starts, messages={_messageQueue.Count}");
            while (_messageQueue.Count > 0)
            {
                MessageItem msgItem = _messageQueue.Dequeue();

                MsgBoxView msgBoxView = null;
                await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    msgBoxView = new MsgBoxView()
                    {
                        DataContext = new MsgBoxViewModel(msgItem.Message, msgItem.MessageType)
                    };
                    msgBoxView.Show();
                }));

                await Task.Delay(3000);

                await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    msgBoxView?.Close();
                }));
            }
        }
示例#2
0
        public void AddError(string message)
        {
            Task.Run(async() =>
            {
                MsgBoxView msgBoxView = null;
                await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    msgBoxView = new MsgBoxView()
                    {
                        DataContext = new MsgBoxViewModel(message, MessageType.Error)
                    };
                    msgBoxView.Show();
                }));

                await Task.Delay(3000);

                await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    msgBoxView?.Close();
                }));
            });
        }
示例#3
0
        //double timeToLive,
        public async static void Show(
            string message,
            string title,
            Brush modalAdornerBrush,
            Brush backgroundBrush,
            Brush foregroundTextBrush,
            double width                            = 300,
            double height                           = 180,
            string metroIcon                        = "",
            string imageIcon                        = "",
            double scaleIcon                        = 1,
            double translateXIcon                   = 0,
            double translateYIcon                   = 0,
            string yesLabel                         = "Yes",
            string yesMessengerContent              = "",
            string yesMessengerIdentifier           = "",
            string noLabel                          = "No",
            string noMessengerContent               = "",
            string noMessengerIdentifier            = "",
            GeneralSystemWideMessage msgToPassAlong = null
            )
        {
            if (MsgBoxService._rootControl != null)
            {
                DispatchedHandler invokedHandler = new DispatchedHandler(() =>
                {
                    if (MsgBoxService._rootControl == null) //|| MsgBoxService._rootControl.Visibility == Visibility.Visible)
                    {
                        return;
                    }


                    //modal adorner
                    Rectangle rectModalAdorner           = new Rectangle();
                    rectModalAdorner.Fill                = modalAdornerBrush;
                    rectModalAdorner.Opacity             = 0.4;
                    rectModalAdorner.HorizontalAlignment = HorizontalAlignment.Stretch;
                    rectModalAdorner.VerticalAlignment   = VerticalAlignment.Stretch;
                    rectModalAdorner.SetValue(Canvas.ZIndexProperty, -2);
                    MsgBoxService._rootControl.Children.Add(rectModalAdorner);


                    //message background
                    Rectangle rectBackground           = new Rectangle();
                    rectBackground.Fill                = backgroundBrush;
                    rectBackground.HorizontalAlignment = HorizontalAlignment.Stretch;
                    rectBackground.VerticalAlignment   = VerticalAlignment.Center;
                    rectBackground.Height              = height + 80;
                    rectBackground.SetValue(Canvas.ZIndexProperty, -1);
                    MsgBoxService._rootControl.Children.Add(rectBackground);


                    MsgBoxService._rootControl.Visibility = Visibility.Visible;

                    //message
                    MsgBoxView msgBoxView = new MsgBoxView(
                        message,
                        "",
                        foregroundTextBrush,
                        metroIcon: metroIcon,
                        imageIcon: imageIcon,
                        scaleIcon: scaleIcon,
                        translateXIcon: translateXIcon,
                        translateYIcon: translateYIcon,
                        yesLabel: yesLabel,
                        yesMessengerContent: yesMessengerContent,
                        yesMessengerIdentifier: yesMessengerIdentifier,
                        noLabel: noLabel,
                        noMessengerContent: noMessengerContent,
                        noMessengerIdentifier: noMessengerIdentifier,
                        msgToPassAlong: msgToPassAlong
                        );

                    msgBoxView.Width  = width;
                    msgBoxView.Height = height;
                    msgBoxView.Margin = new Thickness(3);
                    msgBoxView.HorizontalAlignment        = HorizontalAlignment.Center;
                    msgBoxView.VerticalAlignment          = VerticalAlignment.Center;
                    msgBoxView.BackgroundFill             = backgroundBrush;
                    msgBoxView.MessageTextForegroundColor = foregroundTextBrush;
                    //msgBoxView.OnClosing += new EventHandler(MsgBoxService.view_OnClosing);
                    msgBoxView.Show();

                    MsgBoxService._rootControl.Children.Add(msgBoxView);


                    //MsgBoxService._MsgboxContainer.Children.Insert(0, msgBoxView);
                });
                await MsgBoxService._rootControl.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, invokedHandler);
            }
        }