예제 #1
0
        /// <summary>
        ///     Forwards Executed events to CommandBindings.
        /// </summary>
        internal static void OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if ((sender != null) && (e != null) && (e.Command != null))
            {
                FindCommandBinding(sender, e, e.Command, true);

                if (!e.Handled && (e.RoutedEvent == ExecutedEvent))
                {
                    DependencyObject d = sender as DependencyObject;
                    if (d != null)
                    {
                        if (FocusManager.GetIsFocusScope(d))
                        {
                            // This element is a focus scope.
                            // Try to transfer the event to its parent focus scope's focused element.
                            IInputElement focusedElement = GetParentScopeFocusedElement(d);
                            if (focusedElement != null)
                            {
                                TransferEvent(focusedElement, e);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        internal static bool IsFocusable(DependencyObject element)
        {
            // CODE



            if (element == null)
            {
                return(false);
            }

            UIElement uie = element as UIElement;

            if (uie != null)
            {
                if (uie.IsVisible == false)
                {
                    return(false);
                }
            }

            if ((bool)element.GetValue(UIElement.IsEnabledProperty) == false)
            {
                return(false);
            }

            // CODE



            bool hasModifiers = false;
            BaseValueSourceInternal valueSource = element.GetValueSource(UIElement.FocusableProperty, null, out hasModifiers);
            bool focusable = (bool)element.GetValue(UIElement.FocusableProperty);

            if (!focusable && valueSource == BaseValueSourceInternal.Default && !hasModifiers)
            {
                // The Focusable property was not explicitly set to anything.
                // The default value is generally false, but true in a few cases.

                if (FocusManager.GetIsFocusScope(element))
                {
                    // Focus scopes are considered focusable, even if
                    // the Focusable property is false.
                    return(true);
                }
                else if (uie != null && uie.InternalVisualParent == null)
                {
                    PresentationSource presentationSource = PresentationSource.CriticalFromVisual(uie);
                    if (presentationSource != null)
                    {
                        // A UIElements that is the root of a PresentationSource is considered focusable.
                        return(true);
                    }
                }
            }

            return(focusable);
        }
예제 #3
0
파일: Keyboard.cs 프로젝트: sososu/wpf
        internal static bool IsFocusable(DependencyObject element)
        {
            // This should really be its own property, but it is hard to do efficiently.
            if (element == null)
            {
                return(false);
            }

            UIElement uie = element as UIElement;

            if (uie != null)
            {
                if (uie.IsVisible == false)
                {
                    return(false);
                }
            }

            if ((bool)element.GetValue(UIElement.IsEnabledProperty) == false)
            {
                return(false);
            }

            // There are too many conflicting desires for whether or not
            // an element is focusable.  We need to differentiate between
            // a false default value, and the user specifying false
            // explicitly.
            //
            bool hasModifiers = false;
            BaseValueSourceInternal valueSource = element.GetValueSource(UIElement.FocusableProperty, null, out hasModifiers);
            bool focusable = (bool)element.GetValue(UIElement.FocusableProperty);

            if (!focusable && valueSource == BaseValueSourceInternal.Default && !hasModifiers)
            {
                // The Focusable property was not explicitly set to anything.
                // The default value is generally false, but true in a few cases.

                if (FocusManager.GetIsFocusScope(element))
                {
                    // Focus scopes are considered focusable, even if
                    // the Focusable property is false.
                    return(true);
                }
                else if (uie != null && uie.InternalVisualParent == null)
                {
                    PresentationSource presentationSource = PresentationSource.CriticalFromVisual(uie);
                    if (presentationSource != null)
                    {
                        // A UIElements that is the root of a PresentationSource is considered focusable.
                        return(true);
                    }
                }
            }

            return(focusable);
        }