Ejemplo n.º 1
0
        private static void OnIsModalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ModalContentPresenter control = (ModalContentPresenter)d;

            if ((bool)e.NewValue == true)
            {
                /*
                 * Cache the keyboard navigation mode of the primary content before setting it to
                 * 'none' so that it can be restored when the modal content is hidden.
                 */
                control.cachedTabNavigationMode         = KeyboardNavigation.GetTabNavigation(control.primaryContentPresenter);
                control.cachedDirectionalNavigationMode = KeyboardNavigation.GetDirectionalNavigation(control.primaryContentPresenter);
                control.cachedFocusedElement            = Keyboard.FocusedElement;

                KeyboardNavigation.SetTabNavigation(control.primaryContentPresenter, KeyboardNavigationMode.None);
                KeyboardNavigation.SetDirectionalNavigation(control.primaryContentPresenter, KeyboardNavigationMode.None);

                /*
                 * Show the overlay (which in turn shows the modal content as it is a child of
                 * the overlay) and move focus to the first logical element.
                 */
                control.overlay.Visibility = Visibility.Visible;
                control.overlay.MoveFocus(traversalDirection);

                control.RaiseModalContentShownEvents();
            }
            else
            {
                /*
                 * Hide the overlay (which also hides the modal content...).
                 */
                control.overlay.Visibility = Visibility.Hidden;

                /*
                 * Restore the cached keyboard navigation value on the primary content and move
                 * focus to its first logical element.
                 */
                KeyboardNavigation.SetTabNavigation(control.primaryContentPresenter, control.cachedTabNavigationMode);
                KeyboardNavigation.SetDirectionalNavigation(control.primaryContentPresenter, control.cachedDirectionalNavigationMode);

                Keyboard.Focus(control.cachedFocusedElement);

                control.primaryContentPresenter.MoveFocus(traversalDirection);
                control.RaiseModalContentHiddenEvents();
            }
        }
Ejemplo n.º 2
0
        private static void OnModalContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ModalContentPresenter control = (ModalContentPresenter)d;

            /*
             * If the ModalContentPresenter already contains modal content then
             * the existing content will need to be removed from the logical tree.
             */
            if (e.OldValue != null)
            {
                control.RemoveLogicalChild(e.OldValue);
            }

            /*
             * Add the new content to the logical tree of the ModalContentPresenter
             * and update the logicalChildren array so that the correct element is returned
             * when it is requested by WPF.
             */
            control.modalContentPresenter.Content = e.NewValue;
            control.AddLogicalChild(e.NewValue);
            control.logicalChildren[1] = e.NewValue;
        }
Ejemplo n.º 3
0
        private static void OnOverlayBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ModalContentPresenter control = (ModalContentPresenter)d;

            control.overlay.Background = (Brush)e.NewValue;
        }