コード例 #1
0
        public static MessageBoxButton Show(MessageBoxInfo info)
        {
            if (info == null)
            {
                return(MessageBoxButton.Close);
            }
            if (String.IsNullOrWhiteSpace(info.Title))
            {
                info.Title = GetFinalWindowTitle();
            }
            if (currentDispatcher.Thread != Thread.CurrentThread && info.CanFreeze)
            {
                info.Freeze();
            }
            DispatcherOperation <MessageBoxButton> op = currentDispatcher.InvokeAsync(
                new Func <MessageBoxButton>(() =>
            {
                window = GetWindow();
                window.Show(info);
                return(window.Result);
            }),
                DispatcherPriority.Normal);

            return(op.Result);
        }
コード例 #2
0
        public static MessageBoxInfo New(MessageBoxType type, string header, string content, MessageBoxFooterButtonsCollection footerButtons = null, Action <MessageBoxButton> action = null)
        {
            MessageBoxInfo result = new MessageBoxInfo
            {
                Title         = header,
                Content       = content,
                Action        = action,
                FooterButtons = footerButtons
            };

            switch (type)
            {
            case MessageBoxType.Question:
                result.IconBrushKey = MessageBoxIconBrushDefaultKeys.Question;
                result.Buttons      = MessageBoxButtons.YesNo;
                break;

            case MessageBoxType.Exception:
                result.IconBrushKey       = MessageBoxIconBrushDefaultKeys.Exception;
                result.ContentTemplateKey = MessageBoxContentTemplateDefaultKeys.Exception;
                result.Buttons            = MessageBoxButtons.OK;
                break;

            case MessageBoxType.Information:
                result.IconBrushKey = MessageBoxIconBrushDefaultKeys.Information;
                result.Buttons      = MessageBoxButtons.OK;
                break;

            case MessageBoxType.Warning:
                result.IconBrushKey = MessageBoxIconBrushDefaultKeys.Warning;
                result.Buttons      = MessageBoxButtons.OK;
                break;
            }
            return(result);
        }
コード例 #3
0
 private static MessageBoxButton ShowWindow(MessageBoxInfo info)
 {
     if (String.IsNullOrWhiteSpace(info.Title))
     {
         info.Title = DefaultWindowTitle;
     }
     return(Show(info));
 }
コード例 #4
0
        public static MessageBoxButton ShowError(string windowTitle, string errorText)
        {
            MessageBoxInfo info = new MessageBoxInfo()
            {
                Title        = GetFinalWindowTitle(windowTitle),
                Buttons      = MessageBoxButtons.OK,
                IconBrushKey = MessageBoxIconBrushDefaultKeys.Error,
                Content      = errorText
            };

            return(ShowWindow(info));
        }
コード例 #5
0
        public static MessageBoxButton ShowInformation(string windowTitle, string infoText)
        {
            MessageBoxInfo info = new MessageBoxInfo()
            {
                Title        = GetFinalWindowTitle(windowTitle),
                Buttons      = MessageBoxButtons.OK,
                Content      = infoText,
                IconBrushKey = MessageBoxIconBrushDefaultKeys.Information
            };

            return(Show(info));
        }
コード例 #6
0
        public static void ShowException(Exception exception, string windowTitle = null, string exceptionHeader = null, string exceptionMessageOverride = null, MessageBoxFooterButtonsCollection footerButtons = null)
        {
            string finalWindowTitle = windowTitle ?? DefaultWindowTitle;

            currentDispatcher.Invoke(new Action(() =>
            {
                MessageBoxInfo info = new MessageBoxInfo
                {
                    Title   = finalWindowTitle,
                    Content = exception != null ?
                              new ExceptionInfo(exceptionHeader, exception.GetType().Name, exceptionMessageOverride ?? exception.Message, exception.StackTrace) :
                              new ExceptionInfo(exceptionHeader, null, exceptionMessageOverride, null),
                    IconBrushKey                 = MessageBoxIconBrushDefaultKeys.Exception,
                    ContentTemplateKey           = MessageBoxContentTemplateDefaultKeys.Exception,
                    AdditionalContentTemplateKey = MessageBoxAdditionalContentTemplateDefaultKeys.Exception,
                    FooterButtons                = footerButtons,
                    Buttons = MessageBoxButtons.OK
                };
                Show(info);
            }));
        }
コード例 #7
0
 public void Show(MessageBoxInfo info)
 {
     Info = info;
     ShowDialog();
 }