/// <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); } } } } } }
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); }
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); }