Example #1
0
        public static MessageBoxResult Show(Window owner, UserControl userControl, string messageBoxText, string caption, MessageBoxImageType imageType, IList<MessageBoxButtonInfo> ctrlButtons)
        {
            var mbox = new MessageBoxModule();

            if (CurrentInstanceIsRunning == true)
            {
                mbox.Message = Msg_IsRunning;
            }
            else
                mbox.Message = messageBoxText;
            mbox.Title = caption;
            mbox.LogolSource = Logol_Image;
            bc = new ButtonCollecion();
            mbox.DataContext = bc;

            switch (imageType)
            {
                case MessageBoxImageType.None:
                    mbox.ImgSource = Infomation_Image;
                    break;
                case MessageBoxImageType.Infomation:
                    mbox.ImgSource = Infomation_Image;
                    break;
                case MessageBoxImageType.Question:
                    mbox.ImgSource = Question_Image;
                    break;
                case MessageBoxImageType.Warning:
                    mbox.ImgSource = Warning_Image;
                    break;
                case MessageBoxImageType.Error:
                    mbox.ImgSource = Error_Image;
                    break;
            }

            if (owner != null)
            {
                mbox.Owner = owner;
                mbox.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }

            if (null != ctrlButtons && ctrlButtons.Count > 0)
            {
                foreach (var btnInfo in ctrlButtons)
                {
                    switch (btnInfo.Result)
                    {
                        case MessageBoxResult.Cancel:
                        case MessageBoxResult.No:
                            {
                                var btn = CreateCtrlButton_ResultFalse(mbox, btnInfo.ContentText, MessageBoxResult.No);
                                btn.Command = new MessageBoxCommand(btnInfo.Action, null);
                                bc.CtrlButtonCollection.Add(btn);
                            }
                            break;
                        case MessageBoxResult.None:
                            {
                                var btn = CreateCtrlButton_ResultNull(mbox, btnInfo.ContentText, MessageBoxResult.None);
                                btn.Command = new MessageBoxCommand(btnInfo.Action, null);
                                bc.CtrlButtonCollection.Add(btn);
                            }
                            break;
                        case MessageBoxResult.OK:
                        case MessageBoxResult.Yes:
                        default:
                            {
                                var btn = CreateCtrlButton_ResultTrue(mbox, btnInfo.ContentText, MessageBoxResult.Yes);
                                btn.Command = new MessageBoxCommand(btnInfo.Action, null);
                                bc.CtrlButtonCollection.Add(btn);
                            }
                            break;
                    }
                }

                bool? result = mbox.ShowDialog();

                mbox.Activate();
                return MessageBoxResult.None;
            }
            else
            {
                return Show(owner, userControl, messageBoxText, caption, imageType, MessageBoxButton.OK);
            }


        }
Example #2
0
        public static MessageBoxResult Show(Window owner, UserControl userControl, string messageBoxText, string caption, MessageBoxImageType imageType, MessageBoxButton button)
        {
            var mbox = new MessageBoxModule();

            if (CurrentInstanceIsRunning == true)
            {
                mbox.Message = Msg_IsRunning;
            }
            else
                mbox.Message = messageBoxText;
            mbox.Title = caption;
            mbox.LogolSource = Logol_Image;
            bc = new ButtonCollecion();
            mbox.DataContext = bc;

            switch (imageType)
            {
                case MessageBoxImageType.None:
                    mbox.ImgSource = Infomation_Image;
                    break;
                case MessageBoxImageType.Infomation:
                    mbox.ImgSource = Infomation_Image;
                    break;
                case MessageBoxImageType.Question:
                    mbox.ImgSource = Question_Image;
                    break;
                case MessageBoxImageType.Warning:
                    mbox.ImgSource = Warning_Image;
                    break;
                case MessageBoxImageType.Error:
                    mbox.ImgSource = Error_Image;
                    break;
            }

            if (owner != null)
            {
                mbox.Owner = owner;
                mbox.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }
            switch (button)
            {
                case MessageBoxButton.OKCancel:

                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultTrue(mbox, Msg_OK, MessageBoxResult.OK));

                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultFalse(mbox, Msg_Cancel, MessageBoxResult.Cancel));
                    break;
                //break;
                case MessageBoxButton.YesNo:
                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultTrue(mbox, Msg_Yes, MessageBoxResult.Yes));

                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultFalse(mbox, Msg_No, MessageBoxResult.No));

                    break;
                case MessageBoxButton.YesNoCancel:
                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultTrue(mbox, Msg_Yes, MessageBoxResult.Yes));

                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultFalse(mbox, Msg_No, MessageBoxResult.No));

                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultFalse(mbox, Msg_Cancel, MessageBoxResult.Cancel));
                    break;
                case MessageBoxButton.OK:
                default:
                    bc.CtrlButtonCollection.Add(CreateCtrlButton_ResultTrue(mbox, Msg_OK, MessageBoxResult.OK));
                    break;
            }
            mbox.Activate();
            bool? result = mbox.ShowDialog();

            switch (button)
            {

                //break;
                case MessageBoxButton.OKCancel:
                    {
                        return result == true ? MessageBoxResult.OK
                            : result == false ? MessageBoxResult.Cancel :
                            MessageBoxResult.None;
                    }
                //break;
                case MessageBoxButton.YesNo:
                    {
                        return result == true ? MessageBoxResult.Yes : MessageBoxResult.No;
                    }
                //break;
                case MessageBoxButton.YesNoCancel:
                    {
                        return result == true ? MessageBoxResult.Yes
                            : result == false ? MessageBoxResult.No :
                            MessageBoxResult.Cancel;
                    }

                case MessageBoxButton.OK:
                default:
                    {
                        return result == true ? MessageBoxResult.OK : MessageBoxResult.None;
                    }
            }
        }