/// <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;
        }
Esempio n. 2
0
        /// <summary>
        /// Called when the visual layout changes.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event information.</param>
        private void CustomMessageBox_LayoutUpdated(object sender, EventArgs e)
        {
            SwivelTransition backwardIn = new SwivelTransition {
                Mode = SwivelTransitionMode.BackwardIn
            };
            ITransition swivelTransition = backwardIn.GetTransition(this);

            swivelTransition.Completed += (s1, e1) => swivelTransition.Stop();
            swivelTransition.Begin();
            LayoutUpdated -= CustomMessageBox_LayoutUpdated;
        }
 /// <summary>
 /// Called when the visual layout changes.
 /// </summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event information.</param>
 private void CustomMessageBox_LayoutUpdated(object sender, EventArgs e)
 {
     SwivelTransition backwardIn = new SwivelTransition { Mode = SwivelTransitionMode.BackwardIn };
     ITransition swivelTransition = backwardIn.GetTransition(this);
     swivelTransition.Completed += (s1, e1) => swivelTransition.Stop();
     swivelTransition.Begin();
     LayoutUpdated -= CustomMessageBox_LayoutUpdated;
 }
        /// <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;
        }
 private void Insert()
 {
     // Make an assumption that this is within a phone application that is developed "normally"
     var frame = Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame;
     _page = frame.Content as PhoneApplicationPage;
     _page.BackKeyPress += Page_BackKeyPress;
     // assume the child is a Grid, span all of the rows
     var grid = System.Windows.Media.VisualTreeHelper.GetChild(_page, 0) as Grid;
     if (grid.RowDefinitions.Count > 0)
     {
         Grid.SetRowSpan(this, grid.RowDefinitions.Count);
     }
     grid.Children.Add(this);
     // Create a transition like the regular MessageBox
     SwivelTransition transitionIn = new SwivelTransition();
     transitionIn.Mode = SwivelTransitionMode.BackwardIn;
     // Transition only the MessagePanel
     ITransition transition = transitionIn.GetTransition(MessagePanel);
     transition.Completed += (s, e) => transition.Stop();
     transition.Begin();
     if (_page.ApplicationBar != null)
     {
         // Hide the app bar so they cannot open more message boxes
         _page.ApplicationBar.IsVisible = false;
     }
 }
 private void Remove()
 {
     var frame = Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame;
     var page = frame.Content as PhoneApplicationPage;
     var grid = System.Windows.Media.VisualTreeHelper.GetChild(page, 0) as Grid;
     // Create a transition like the regular MessageBox
     SwivelTransition transitionOut = new SwivelTransition();
     transitionOut.Mode = SwivelTransitionMode.BackwardOut;
     ITransition transition = transitionOut.GetTransition(MessagePanel);
     transition.Completed += (s, e) =>
     {
         transition.Stop();
         grid.Children.Remove(this);
         if (page.ApplicationBar != null)
         {
             page.ApplicationBar.IsVisible = true;
         }
     };
     transition.Begin();
 }