コード例 #1
0
        public MessageBox_Custom(string mainText, string captionText, MessageBoxButton buttons, MessageBoxImage image)
        {
            InitializeComponent();

            tBlock.Text = mainText;
            Title       = captionText;

            var scr = ScreenHelper.GetCurrentScreen(this);

            label.MaxWidth  = scr.Size.Width * 0.75;
            label.MaxHeight = scr.Size.Height * 0.75;

            if (buttons.HasFlag(MessageBoxButton.OK))
            {
                stackPanel.Children.Add(CreateOK());
            }
            if (buttons.HasFlag(MessageBoxButton.Yes))
            {
                stackPanel.Children.Add(CreateYes());
            }
            if (buttons.HasFlag(MessageBoxButton.No))
            {
                stackPanel.Children.Add(CreateNo());
            }
            if (buttons.HasFlag(MessageBoxButton.Cancel))
            {
                stackPanel.Children.Add(CreateCancel());
            }

            if (image != MessageBoxImage.None)
            {
                MahApps.Metro.IconPacks.PackIconMaterial icon = new MahApps.Metro.IconPacks.PackIconMaterial()
                {
                    Foreground          = App.Current.Resources["AccentColor"] as Brush,
                    Height              = 64,
                    Width               = 64,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Margin              = new Thickness(10)
                };

                switch (image)
                {
                case MessageBoxImage.Error:
                    icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.CloseCircleOutline;
                    break;

                case MessageBoxImage.Exclamation:
                    icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.AlertCircleOutline;
                    break;

                case MessageBoxImage.Information:
                    icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.InformationOutline;
                    break;

                case MessageBoxImage.Question:
                    icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.HelpCircleOutline;
                    break;
                }

                grid.Children.Add(icon);
            }
        }