private static void OnIsAutomationFocusedChanged(DependencyObject dobj, DependencyPropertyChangedEventArgs e) { if (AutomationPeerCache._objThatIsBinding == dobj) { return; } AutomationPeer automationPeer = AutomationPeerCache.GetAutomationPeer(dobj) ?? UIElementAutomationPeer.FromElement(dobj as UIElement); if (automationPeer == null) { return; } if (AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged)) { automationPeer.RaisePropertyChangedEvent(SelectionItemPatternIdentifiers.IsSelectedProperty, e.OldValue, e.NewValue); automationPeer.RaisePropertyChangedEvent(AutomationElementIdentifiers.HasKeyboardFocusProperty, e.OldValue, e.NewValue); } if (AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged)) { automationPeer.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged); } if (!(automationPeer is ItemAutomationPeer) || !AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected)) { return; } automationPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); }
public static T Create <T>(UIElement element, params object[] args) where T : AutomationPeer { AutomationPeer automationPeer = AutomationPeerCache.GetAutomationPeer((DependencyObject)element); if (automationPeer == null) { if (args.Length == 0) { automationPeer = (AutomationPeer)Activator.CreateInstance(typeof(T), new object[1] { (object)element }); } else { automationPeer = (AutomationPeer)Activator.CreateInstance(typeof(T), args); } if (automationPeer != null) { AutomationPeerCache.SetAutomationPeer((DependencyObject)element, automationPeer); AutomationPeerCache.RegisterFocusEvents((DependencyObject)element); } } return(automationPeer as T); }
public static void RegisterFocusEvents(DependencyObject obj, AutomationPeer associatedPeer) { if (AutomationPeerCache.GetIsAutomationFocused(obj)) { return; } if (AutomationPeerCache.GetAutomationPeer(obj) == null && UIElementAutomationPeer.FromElement(obj as UIElement) == null) { AutomationPeerCache.SetAutomationPeer(obj, associatedPeer); } AutomationPeerCache.RegisterFocusEvents(obj, "IsKeyboardFocused"); }