示例#1
0
        private static void OnMessageBoxButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MessageBoxCard card = d as MessageBoxCard;

            if (card != null)
            {
                switch ((MessageBoxButton)e.NewValue)
                {
                case MessageBoxButton.OK:
                default:
                    card.IsShowOk     = true;
                    card.IsShowCancel = false;
                    card.IsShowYes    = false;
                    card.IsShowNo     = false;
                    break;

                case MessageBoxButton.OKCancel:
                    card.IsShowOk     = true;
                    card.IsShowCancel = true;
                    card.IsShowYes    = false;
                    card.IsShowNo     = false;
                    break;

                case MessageBoxButton.YesNoCancel:
                    card.IsShowOk     = false;
                    card.IsShowCancel = true;
                    card.IsShowYes    = true;
                    card.IsShowNo     = true;
                    break;

                case MessageBoxButton.YesNo:
                    card.IsShowOk     = false;
                    card.IsShowCancel = false;
                    card.IsShowYes    = true;
                    card.IsShowNo     = true;
                    break;
                }
            }
        }
示例#2
0
        public static MessageBoxResult Show(string message, string title = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxIcon icon = MessageBoxIcon.None)
        {
            MessageBoxCard card = new MessageBoxCard
            {
                Content          = message,
                Title            = title,
                MessageBoxButton = button,
                ShowShadow       = false
            };

            card.Dispatcher.VerifyAccess();

            switch (icon)
            {
            case MessageBoxIcon.None:
                card.IsShowIcon = false;
                break;

            case MessageBoxIcon.Info:
                card.IsShowIcon      = true;
                card.IconType        = IconType.InformationFill;
                card.ThemeColorBrush = infoBrush;
                break;

            case MessageBoxIcon.Success:
                card.IsShowIcon      = true;
                card.IconType        = IconType.CheckboxCircleFill;
                card.ThemeColorBrush = successBrush;
                break;

            case MessageBoxIcon.Warining:
                card.IsShowIcon      = true;
                card.IconType        = IconType.ErrorWarningFill;
                card.ThemeColorBrush = warningBrush;
                break;

            case MessageBoxIcon.Error:
                card.IsShowIcon      = true;
                card.IconType        = IconType.CloseCircleFill;
                card.ThemeColorBrush = errorBrush;
                break;

            case MessageBoxIcon.Question:
                card.IsShowIcon      = true;
                card.IconType        = IconType.QuestionFill;
                card.ThemeColorBrush = questionBrush;
                break;
            }

            MessageBoxWindow window = new MessageBoxWindow();

            window.AddMessageBoxCard(card);

            var windows = Application.Current.Windows;

            for (int i = 0; i < windows.Count; i++)
            {
                if (windows[i].IsActive)
                {
                    window.Owner = windows[i];
                }
            }

            if (window.ShowDialog() == true)
            {
                return(window.MessageBoxResult);
            }

            return(MessageBoxResult.Cancel);
        }
示例#3
0
        public static async Task <MessageBoxResult> ShowInContainer(string containerIdentifier, string message, string title = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxIcon icon = MessageBoxIcon.None)
        {
            MessageBoxResult result         = MessageBoxResult.No;
            bool             isReturnResult = false;

            if (!MessageBoxContainer.Containers.ContainsKey(containerIdentifier))
            {
                return(result);
            }

            MessageBoxContainer container = MessageBoxContainer.Containers[containerIdentifier];

            container.Dispatcher.VerifyAccess();

            MessageBoxCard card = new MessageBoxCard
            {
                Content          = message,
                Title            = title,
                MessageBoxButton = button,
            };

            card.ReturnResult += (a, b) =>
            {
                isReturnResult = true;
                result         = b.Result;
            };

            switch (icon)
            {
            case MessageBoxIcon.None:
                card.IsShowIcon = false;
                break;

            case MessageBoxIcon.Info:
                card.IsShowIcon      = true;
                card.IconType        = IconType.InformationFill;
                card.ThemeColorBrush = infoBrush;
                break;

            case MessageBoxIcon.Success:
                card.IsShowIcon      = true;
                card.IconType        = IconType.CheckboxCircleFill;
                card.ThemeColorBrush = successBrush;
                break;

            case MessageBoxIcon.Warining:
                card.IsShowIcon      = true;
                card.IconType        = IconType.ErrorWarningFill;
                card.ThemeColorBrush = warningBrush;
                break;

            case MessageBoxIcon.Error:
                card.IsShowIcon      = true;
                card.IconType        = IconType.CloseCircleFill;
                card.ThemeColorBrush = errorBrush;
                break;

            case MessageBoxIcon.Question:
                card.IsShowIcon      = true;
                card.IconType        = IconType.QuestionFill;
                card.ThemeColorBrush = questionBrush;
                break;
            }

            container.Visibility = Visibility.Visible;

            // 动画
            Storyboard cardStoryboard = new Storyboard();

            DoubleAnimation opacityAnimation = new DoubleAnimation
            {
                From           = 0,
                To             = 1,
                Duration       = new Duration(TimeSpan.FromMilliseconds(200)),
                EasingFunction = new CubicEase {
                    EasingMode = EasingMode.EaseOut
                }
            };

            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(UIElement.OpacityProperty));

            DoubleAnimation transformAnimation = new DoubleAnimation
            {
                From           = 50,
                To             = 0,
                Duration       = new Duration(TimeSpan.FromMilliseconds(200)),
                EasingFunction = new CubicEase {
                    EasingMode = EasingMode.EaseOut
                }
            };

            Storyboard.SetTargetProperty(transformAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));

            cardStoryboard.Children.Add(opacityAnimation);
            cardStoryboard.Children.Add(transformAnimation);

            // 背景动画
            ColorAnimation backgroundAnimation = new ColorAnimation
            {
                From           = Colors.Transparent,
                To             = containerBackgroun,
                Duration       = new Duration(TimeSpan.FromMilliseconds(150)),
                EasingFunction = new CubicEase {
                    EasingMode = EasingMode.EaseOut
                }
            };

            backgroundAnimation.Completed += (sender, e) =>
            {
                container.Child = card;
                card.BeginStoryboard(cardStoryboard);
                card.Focus();
            };

            container.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundAnimation);

            await Task.Run(() => { while (!isReturnResult)
                                   {
                                       Thread.Sleep(10);
                                   }
                           });

            return(result);
        }
 public void AddMessageBoxCard(MessageBoxCard card)
 {
     card.ReturnResult += Card_ReturnResult;
     messageBoxPanel.Children.Add(card);
 }
示例#5
0
 public MessageBoxResultRoutedEventArge(RoutedEvent routedEvent, MessageBoxResult result, MessageBoxCard card) : base(routedEvent)
 {
     Result = result;
     Card   = card;
 }