/// <summary>
        /// Dismisses the message box.
        /// </summary>
        /// <param name="source">
        /// The source that caused the dismission.
        /// </param>
        /// <param name="useTransition">
        /// If true, the message box is dismissed after swiveling
        /// backward and out.
        /// </param>
        private void Dismiss(CustomMessageBoxResult source, bool useTransition)
        {
            // Ensure only a single Dismiss is being handled at a time
            if (_isBeingDismissed)
            {
                return;
            }
            _isBeingDismissed = true;

            // Handle the dismissing event.
            var handlerDismissing = Dismissing;

            if (handlerDismissing != null)
            {
                DismissingEventArgs args = new DismissingEventArgs(source);
                handlerDismissing(this, args);

                if (args.Cancel)
                {
                    _isBeingDismissed = false;
                    return;
                }
            }

            // Handle the dismissed event.
            var handlerDismissed = Dismissed;

            if (handlerDismissed != null)
            {
                DismissedEventArgs args = new DismissedEventArgs(source);
                handlerDismissed(this, args);
            }

            // Set the current instance to null.
            _currentInstance = null;

            // Cache this variable to avoid a race condition.
            bool restoreOriginalValues = _mustRestore;

            // Close popup.
            if (useTransition)
            {
                SwivelTransition backwardOut = new SwivelTransition {
                    Mode = SwivelTransitionMode.BackwardOut
                };
                ITransition swivelTransition = backwardOut.GetTransition(this);
                swivelTransition.Completed += (s, e) =>
                {
                    swivelTransition.Stop();
                    ClosePopup(restoreOriginalValues);
                };
                swivelTransition.Begin();
            }
            else
            {
                ClosePopup(restoreOriginalValues);
            }

            _isBeingDismissed = false;
        }
        /// <summary>
        /// Closes the pop up.
        /// </summary>
        private void ClosePopup(bool restoreOriginalValues, CustomMessageBoxResult source)
        {
            // Remove the popup.
            if (_popup != null)
            {
                _popup.IsOpen = false;
                _popup        = null;
            }

            // If there is no other message box displayed.
            if (restoreOriginalValues)
            {
                // Set the system tray back to its original
                // color nad opacity if necessary.
                if (SystemTray.IsVisible)
                {
                    SystemTray.BackgroundColor = _systemTrayColor;
                    SystemTray.Opacity         = _systemTrayOpacity;
                }

                // Bring the application bar if necessary.
                if (_hasApplicationBar)
                {
                    _hasApplicationBar = false;

                    // Application bar can be nulled during the Dismissed event
                    // so a null check needs to be performed here.
                    if (_page.ApplicationBar != null)
                    {
                        _page.ApplicationBar.IsVisible = true;
                    }
                }
            }

            // Dettach event handlers.
            if (_page != null)
            {
                _page.BackKeyPress       -= OnBackKeyPress;
                _page.OrientationChanged -= OnOrientationChanged;
                _page = null;
            }

            if (_frame != null)
            {
                _frame.Navigating -= OnNavigating;
                _frame             = null;
            }

            // Handle the dismissed event.
            var handlerDismissed = Dismissed;

            if (handlerDismissed != null)
            {
                DismissedEventArgs args = new DismissedEventArgs(source);
                handlerDismissed(this, args);
            }
        }
 protected virtual void OnClosed(CustomMessageBoxResult result)
 {
     // need to unsubscribe from the backkeypress
     _page.BackKeyPress -= Page_BackKeyPress;
     var handler = this.Closed;
     if (handler != null)
     {
         handler(this, new MessageBoxEventArgs
         {
             Result = result
         });
     }
     Remove();
 }
Example #4
0
        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            Button clicked = sender as Button;
            string name    = clicked.Name;

            switch (name.ToUpper())
            {
            case "YES":
                _result = CustomMessageBoxResult.Yes;
                break;

            case "NO":
                _result = CustomMessageBoxResult.No;
                break;

            case "OK":
                _result = CustomMessageBoxResult.OK;
                break;
            }

            Close();
        }
        public Dialog(CustomMessageBoxButton Buttons)
        {
            InitializeComponent();
            this.DataContext = this;

            Result = CustomMessageBoxResult.None;
            BitmapImage imgSource = new BitmapImage(new Uri(@"logo.ico", UriKind.Relative));

            image_logo.Source = imgSource;
            this.Buttons      = Buttons;
            switch (Buttons)
            {
            case CustomMessageBoxButton.OK:
                btn_ok.Content        = "确 定";
                btn_cancel.Visibility = Visibility.Collapsed;
                btn_yes.Visibility    = Visibility.Collapsed;
                break;

            case CustomMessageBoxButton.OKCancel:
                btn_ok.Content     = "确 定";
                btn_cancel.Content = "取 消";
                btn_yes.Visibility = Visibility.Collapsed;
                break;

            case CustomMessageBoxButton.YesNo:
                btn_cancel.Content = "否";
                btn_ok.Visibility  = Visibility.Collapsed;
                break;

            case CustomMessageBoxButton.YesNoCancel:
                break;

            default:
                break;
            }
        }
Example #6
0
 // Methods
 public DismissedEventArgs(CustomMessageBoxResult result)
 {
     this.Result = result;
 }
        /// <summary>
        /// Closes the pop up.
        /// </summary>
        private void ClosePopup(bool restoreOriginalValues, CustomMessageBoxResult source)
        {
            // Remove the popup.
            if (_popup != null)
            {
                _popup.IsOpen = false;
                _popup = null;
            }

            // If there is no other message box displayed.  
            if (restoreOriginalValues)
            {
                // Set the system tray back to its original 
                // color nad opacity if necessary.
                if (SystemTray.IsVisible)
                {
                    SystemTray.BackgroundColor = _systemTrayColor;
                    SystemTray.Opacity = _systemTrayOpacity;
                }

                // Bring the application bar if necessary.
                if (_hasApplicationBar)
                {
                    _hasApplicationBar = false;

                    // Application bar can be nulled during the Dismissed event
                    // so a null check needs to be performed here.
                    if (_page.ApplicationBar != null)
                    {
                        _page.ApplicationBar.IsVisible = true;
                    }
                }
            }

            // Dettach event handlers.
            if (_page != null)
            {
                _page.BackKeyPress -= OnBackKeyPress;
                _page.OrientationChanged -= OnOrientationChanged;
                _page = null;
            }

            if (_frame != null)
            {
                _frame.Navigating -= OnNavigating;
                _frame = null;
            }

            // Handle the dismissed event.
            var handlerDismissed = Dismissed;
            if (handlerDismissed != null)
            {
                DismissedEventArgs args = new DismissedEventArgs(source);
                handlerDismissed(this, args);
            }
        }
        /// <summary>
        /// Dismisses the message box.
        /// </summary>
        /// <param name="source">
        /// The source that caused the dismission.
        /// </param>
        /// <param name="useTransition">
        /// If true, the message box is dismissed after swiveling
        /// backward and out.
        /// </param>
        private void Dismiss(CustomMessageBoxResult source, bool useTransition)
        {
            // Ensure only a single Dismiss is being handled at a time
            if (_isBeingDismissed)
            {
                return;
            }
            _isBeingDismissed = true;

            // Handle the dismissing event.
            var handlerDismissing = Dismissing;
            if (handlerDismissing != null)
            {
                DismissingEventArgs args = new DismissingEventArgs(source);
                handlerDismissing(this, args);

                if (args.Cancel)
                {
                    _isBeingDismissed = false;
                    return;
                }
            }

            // Set the current instance to null.
            _currentInstance = null;

            // Cache this variable to avoid a race condition.
            bool restoreOriginalValues = _mustRestore;

            // Close popup.
            if (useTransition)
            {
                SwivelTransition backwardOut = new SwivelTransition { Mode = SwivelTransitionMode.BackwardOut };
                ITransition swivelTransition = backwardOut.GetTransition(this);
                swivelTransition.Completed += (s, e) =>
                {
                    swivelTransition.Stop();
                    ClosePopup(restoreOriginalValues, source);
                };
                swivelTransition.Begin();
            }
            else
            {
                ClosePopup(restoreOriginalValues, source);
            }

            _isBeingDismissed = false;
        }
Example #9
0
 //***********************************************************************************************************************
 /// <summary>
 /// Initializes a new instance of the DismissingEventArgs class.
 /// </summary>
 /// <param name="result">The result value.</param>
 //-----------------------------------------------------------------------------------------------------------------------
 public DismissingEventArgs(CustomMessageBoxResult Result)
 {
     this.Result = Result;
 }
 public static void SetupCustomMessageBoxResult(this Mock <IMessageService> mock, CustomMessageBoxResult result)
 {
     mock.SetupTask <IMessageService, CustomMessageBoxResult>(s => s.ShowCustomMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
     .ReturnsResult(result);
 }
 public DismissedEventArgs(CustomMessageBoxResult result)
 {
     this.Result = result;
 }
        private void ProcessButtonClick(CustomMessageBoxResult c)
        {
            if (this.Dismissing != null)
            {
                var dea = new DismissingEventArgs(c);
                this.Dismissing(this, dea);
                if (dea.Cancel == true)
                {
                    return;
                }
            }

#if NETFX_CORE
            this.Dismiss();
#else 
            this.Close();
#endif

            if (this.Dismissed != null)
            {
                this.Dismissed(this, new DismissedEventArgs(c));
            }
        }
 private void OkButton_Click(object sender, RoutedEventArgs e)
 {
     Result = CustomMessageBoxResult.OK;
     this.Close();
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the DismissingEventArgs class.
 /// </summary>
 /// <param name="result">The result value.</param>
 public DismissingEventArgs(CustomMessageBoxResult result)
 {
     Result = result;
 }
 private void me3button_Click(object sender, RoutedEventArgs e)
 {
     _result = CustomMessageBoxResult.ME3;
     Close();
 }
  /// <summary>
 /// Initializes a new instance of the DismissingEventArgs class.
 /// </summary>
 /// <param name="result">The result value.</param>
 public DismissingEventArgs(CustomMessageBoxResult result)
 {
     Result = result;
 }
Example #17
0
 private void me3button_Click(object sender, RoutedEventArgs e)
 {
     _result = CustomMessageBoxResult.ME3;
     Close();
 }