Exemple #1
0
        public void Close(EMessageBoxResult result)
        {
            LastResult = result;
            void Finalize()
            {
                Hide();                 //hide window
                if (OnResult != null)
                {
                    //support chaining of windows, like "are you sure?". Prevent double-calling and lost callbacks
                    //MessageBoxResultCallback temp = OnResult.Clone() as MessageBoxResultCallback;
                    MessageBoxResultCallback temp = OnResult; //copy
                    OnResult = null;                          //remove so next window could subscribe
                    temp(LastResult);                         //can still call events without overlap
                }
            }

            ToggleButtonInteractivity(false);             //disable, but don't hide.

            if (animate && transitionOUTAnimator != null)
            {
                transitionOUTAnimator.Animate(windowTransform, Finalize);
            }
            else
            {
                Finalize();
            }
        }
Exemple #2
0
        public void Show(string messageBoxText, string messageBoxTitle = ConstStrings.EMPTY,
                         EMessageBoxButton style = EMessageBoxButton.OK,
                         bool animate            = false,
                         MessageBoxResultCallback resultCallback = null,
                         string button1Text = null,
                         string button2Text = null,
                         string button3Text = null)
        {
            this.animate    = animate;
            this.Style      = style;
            promptText.text = messageBoxText;
            titleText.text  = messageBoxTitle;

            OnResult = resultCallback;

            switch (style)
            {
            case EMessageBoxButton.OK:
                Debug.Assert(string.IsNullOrEmpty(button2Text), "Too many button texts supplied.");
                Debug.Assert(string.IsNullOrEmpty(button3Text), "Too many button texts supplied.");
                SetupSingleButton(button1Text);
                break;

            case EMessageBoxButton.OKCancel:
                Debug.Assert(string.IsNullOrEmpty(button3Text), "Too many button texts supplied.");
                SetupDoubleButton(button1Text, button2Text);
                break;

            case EMessageBoxButton.YesNo:
                Debug.Assert(string.IsNullOrEmpty(button3Text), "Too many button texts supplied.");
                SetupDoubleButton(button1Text, button2Text);
                break;

            case EMessageBoxButton.YesNoCancel:
                SetupTripleButton(button1Text, button2Text, button3Text);
                break;

            default:
                throw new NotImplementedException($"{style} not implemented.");
            }

            Show();            //show visuals
            if (animate && transitionINAnimator != null)
            {
                ToggleButtonInteractivity(false);                 //disallow interaction until open.
                transitionINAnimator.Animate(windowTransform,
                                             onCompleteCallback: () => ToggleButtonInteractivity(true));
            }
        }
Exemple #3
0
        private MessageBox(string text, string caption, MessageBoxButton button, MessageBoxImage icon,
                           MessageBoxResult defaultResult, MessageBoxResultCallback callback)
        {
            _callback = callback;

            MessageBoxResult defaultButton = GetDefaultButton(button, defaultResult);

            DelegateCommand close = new DelegateCommand((parameter) =>
            {
                Application.Current.MainWindow.RemoveLayer(this);
                _callback((MessageBoxResult)parameter);
            });

            SetValue(MessageBoxTextProperty, text);
            SetValue(MessageBoxCaptionProperty, caption);
            SetValue(MessageBoxButtonProperty, button);
            SetValue(MessageBoxDefaultButtonProperty, defaultButton);
            SetValue(MessageBoxIconProperty, icon);
            SetValue(MessageBoxCloseProperty, close);

            GUI.LoadComponent(this, "Src/Core/MessageBox.xaml");
        }
Exemple #4
0
 /// <summary>
 /// Displays a message box that has a message, title bar caption, and button; and uses the
 /// callback to notify the result.
 /// </summary>
 public static void Show(string text, string caption, MessageBoxButton button,
                         MessageBoxResultCallback callback)
 {
     Show(text, caption, button, MessageBoxImage.None, MessageBoxResult.None, callback);
 }
Exemple #5
0
 /// <summary>
 /// Displays a message box that has a message and that uses the callback to notify the result.
 /// </summary>
 public static void Show(string text, MessageBoxResultCallback callback)
 {
     Show(text, "", MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, callback);
 }
Exemple #6
0
        /// <summary>
        /// Displays a message box that has a message, title bar caption, button, and icon; and that
        /// accepts a default message box result and that uses the callback to notify the result.
        /// </summary>
        public static void Show(string text, string caption, MessageBoxButton button,
                                MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxResultCallback callback)
        {
            MessageBox messageBox = new MessageBox(text, caption, button, icon, defaultResult, callback);

            Application.Current.MainWindow.AddLayer(messageBox);
        }