public override void GetName_AttachedProperty0Event() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } TextBox fe = CreateConcreteFrameworkElement() as TextBox; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(fe); AutomationPropertyEventTuple tuple = null; CreateAsyncTest(fe, () => { EventsManager.Instance.Reset(); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNull(tuple, "#0"); }, () => { EventsManager.Instance.Reset(); fe.SetValue(AutomationProperties.NameProperty, "Attached Name"); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#1"); Assert.AreEqual("Attached Name", (string)tuple.NewValue, "#2"); Assert.AreEqual(string.Empty, tuple.OldValue, "#3"); }, () => { EventsManager.Instance.Reset(); fe.SetValue(AutomationProperties.NameProperty, "Name"); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#4"); Assert.AreEqual("Name", (string)tuple.NewValue, "#5"); Assert.AreEqual("Attached Name", (string)tuple.OldValue, "#6"); }, () => { // Even if TextBox.Name changes the value will be the same EventsManager.Instance.Reset(); fe.Text = "New value"; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNull(tuple, "#7"); }, () => { EventsManager.Instance.Reset(); fe.SetValue(AutomationProperties.NameProperty, null); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#8"); Assert.AreEqual("New value", (string)tuple.NewValue, "#9"); Assert.AreEqual("Name", (string)tuple.OldValue, "#10"); }, () => { EventsManager.Instance.Reset(); fe.Text = "What's up?"; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#11"); Assert.AreEqual("What's up?", (string)tuple.NewValue, "#12"); Assert.AreEqual("New value", (string)tuple.OldValue, "#13"); }); }
/// <summary> /// Returns an automation peer for the underlying /// <see cref="T:System.Windows.Controls.Primitives.Selector" /> /// control, for use by the Silverlight automation infrastructure. /// </summary> /// <returns>An automation peer for use by the Silverlight automation /// infrastructure.</returns> public AutomationPeer CreateAutomationPeer() { return(_selector != null?FrameworkElementAutomationPeer.CreatePeerForElement(_selector) : null); }
public override void GetName_AttachedProperty0Event() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } ButtonBase fe = CreateConcreteFrameworkElement() as ButtonBase; TextBlock textblock = new TextBlock() { Text = "Textblock" }; fe.Content = textblock; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(fe); AutomationPropertyEventTuple tuple = null; CreateAsyncTest(fe, () => { EventsManager.Instance.Reset(); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNull(tuple, "#0"); }, () => { EventsManager.Instance.Reset(); textblock.Text = "Hi"; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#1"); Assert.AreEqual("Hi", (string)tuple.NewValue, "#2"); Assert.AreEqual("Textblock", tuple.OldValue, "#3"); }, () => { EventsManager.Instance.Reset(); fe.SetValue(AutomationProperties.NameProperty, "Attached Name"); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#4"); Assert.AreEqual("Attached Name", (string)tuple.NewValue, "#5"); Assert.AreEqual("Hi", tuple.OldValue, "#6"); }, () => { EventsManager.Instance.Reset(); fe.SetValue(AutomationProperties.NameProperty, "Name"); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#7"); Assert.AreEqual("Name", (string)tuple.NewValue, "#8"); Assert.AreEqual("Attached Name", (string)tuple.OldValue, "#9"); }, () => { // Even if change TextBlock.Text (our current Content) the value will be the same EventsManager.Instance.Reset(); textblock.Text = "New value"; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNull(tuple, "#10"); }, () => { EventsManager.Instance.Reset(); fe.SetValue(AutomationProperties.NameProperty, null); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#11"); Assert.AreEqual("New value", (string)tuple.NewValue, "#12"); Assert.AreEqual("Name", (string)tuple.OldValue, "#13"); }, () => { EventsManager.Instance.Reset(); textblock.Text = "What's up?"; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#14"); Assert.AreEqual("What's up?", (string)tuple.NewValue, "#15"); Assert.AreEqual("New value", (string)tuple.OldValue, "#16"); }, () => { EventsManager.Instance.Reset(); fe.Content = "Hola"; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.NameProperty); Assert.IsNotNull(tuple, "#17"); Assert.AreEqual("Hola", (string)tuple.NewValue, "#18"); Assert.AreEqual("What's up?", (string)tuple.OldValue, "#19"); }); }
public virtual void ToggleProvider_ToggleEvents() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } ToggleButton toggleButton = CreateConcreteFrameworkElement() as ToggleButton; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(toggleButton); AutomationPropertyEventTuple tuple = null; IToggleProvider toggleProvider = (IToggleProvider)peer; CreateAsyncTest(toggleButton, () => { EventsManager.Instance.Reset(); toggleButton.IsThreeState = false; toggleButton.IsChecked = false; }, // Test two-state toggling () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNull(tuple, "#0"); Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "Start two-state toggle: Unchecked"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#1"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.OldValue, "#2"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.NewValue, "#3"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#4"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.OldValue, "#5"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.NewValue, "#6"); }, // Test three-state toggling () => { EventsManager.Instance.Reset(); toggleButton.IsThreeState = true; toggleButton.IsChecked = true; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#7"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.OldValue, "#8"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.NewValue, "#9"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#10"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.OldValue, "#11"); Assert.AreEqual(ToggleState.Indeterminate, (ToggleState)tuple.NewValue, "#12"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#13"); Assert.AreEqual(ToggleState.Indeterminate, (ToggleState)tuple.OldValue, "#14"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.NewValue, "#15"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#16"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.OldValue, "#17"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.NewValue, "#18"); }); }
/// <summary> /// Custom keyboard nav behavior /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lviResults_PreviewKeyDown(object sender, KeyEventArgs e) { UIElement uie = e.OriginalSource as UIElement; if ((e.Key == Key.Right || e.Key == Key.Left) && Keyboard.FocusedElement is ListViewItem) { if (e.Key == Key.Right) { var vb = GetFirstChildElement <CheckBox>(sender as DependencyObject) as CheckBox; vb.Focus(); } else { var parent = GetParentElem <Expander>(sender as DependencyObject) as Expander; var vb = GetFirstChildElement <Label>(parent as DependencyObject) as Label; vb.Focus(); } e.Handled = true; } else if ((e.Key == Key.Right || e.Key == Key.Left) && (Keyboard.FocusedElement is CheckBox || Keyboard.FocusedElement is Button)) { var elements = new List <DependencyObject>(); elements.Add(GetFirstChildElement <CheckBox>(sender as DependencyObject)); elements.AddRange(FindChildren <Button>(sender as DependencyObject)); int selectedElementIndex = elements.FindIndex(b => b.Equals(Keyboard.FocusedElement)); if (e.Key == Key.Right) { if (selectedElementIndex + 1 < elements.Count) { ((UIElement)elements.ElementAt(selectedElementIndex + 1)).Focus(); } } else if (selectedElementIndex - 1 >= 0) { ((UIElement)elements.ElementAt(selectedElementIndex - 1)).Focus(); } else { (sender as ListBoxItem).Focus(); } System.Diagnostics.Debug.WriteLine(Keyboard.FocusedElement.ToString() + " " + FrameworkElementAutomationPeer.FromElement(Keyboard.FocusedElement as FrameworkElement)?.HasKeyboardFocus()); FrameworkElementAutomationPeer.FromElement(Keyboard.FocusedElement as FrameworkElement)?.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged); e.Handled = true; } else if (e.Key == Key.Down || e.Key == Key.Up) { (sender as ListViewItem).Focus(); uie = (UIElement)Keyboard.FocusedElement; if (e.Key == Key.Down) { uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down)); } else { var element = uie.PredictFocus(FocusNavigationDirection.Up); if (element is ListViewItem) { uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up)); } else { (GetParentElem <GroupItem>(sender as DependencyObject) as UIElement).Focus(); } } e.Handled = true; } else if (e.Key == Key.Return && Keyboard.FocusedElement is ListViewItem) { var btn = GetFirstChildElement <Button>(sender as DependencyObject) as Button; ButtonElem_Click(btn, e); } }
public override void GetChildrenChanged() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } TabControl tabControl = new TabControl(); TabItem tabItem = new TabItem(); tabControl.Items.Add(tabItem); AutomationPeer peerTab = null; AutomationPeer peer = null; AutomationEventTuple tuple = null; CreateAsyncTest(tabControl, () => { peerTab = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); Assert.IsNotNull(peerTab, "#0"); List <AutomationPeer> children = peerTab.GetChildren(); Assert.IsNotNull(children, "GetChildren #0"); Assert.AreEqual(1, children.Count, "GetChildren.Count #0"); peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem); Assert.IsNotNull(peer, "#0"); children = peer.GetChildren(); Assert.IsNull(children, "GetChildren #1"); }, () => { StackPanel panel = new StackPanel(); tabItem.Content = panel; panel.Children.Add(new TextBlock() { Text = "Content" }); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged); Assert.IsNotNull(tuple, "StructureChanged #0"); List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #2"); Assert.AreEqual(1, children.Count, "GetChildren.Count #2"); }, () => { StackPanel panel = (StackPanel)tabItem.Content; panel.Children.Add(new TextBlock() { Text = "Content" }); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged); Assert.IsNotNull(tuple, "StructureChanged #1"); List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #3"); Assert.AreEqual(2, children.Count, "GetChildren.Count #3"); }); }
public void ISelectionItemProvider_Methods() { TabControl tabControl = new TabControl(); TabItem item0 = new TabItem() { Header = "Item0" }; TabItem item1 = new TabItem() { Header = "Item1" }; TabItem item2 = new TabItem() { Header = "Item2" }; tabControl.Items.Add(item0); tabControl.Items.Add(item1); tabControl.Items.Add(item2); item0.IsSelected = true; AutomationPeer peer0 = null; AutomationPeer peer1 = null; AutomationPeer peer2 = null; ISelectionItemProvider selectionItemProvider0 = null; ISelectionItemProvider selectionItemProvider1 = null; ISelectionItemProvider selectionItemProvider2 = null; CreateAsyncTest(tabControl, () => { AutomationPeer tabControlPeer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); List <AutomationPeer> children = tabControlPeer.GetChildren(); Assert.IsNotNull(children, "GetChildren #0"); Assert.AreEqual(3, children.Count, "GetChildren #1"); peer0 = FrameworkElementAutomationPeer.CreatePeerForElement(item0); peer1 = FrameworkElementAutomationPeer.CreatePeerForElement(item1); peer2 = FrameworkElementAutomationPeer.CreatePeerForElement(item2); selectionItemProvider0 = peer0.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider0, "SelectionItem Provider #1"); selectionItemProvider1 = peer1.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider1, "SelectionItem Provider #2"); selectionItemProvider2 = peer2.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider2, "SelectionItem Provider #3"); Assert.IsTrue(selectionItemProvider0.IsSelected, "IsSelected #1"); Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #2"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #3"); }, () => { selectionItemProvider1.AddToSelection(); }, () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #4"); Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #5"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #6"); }, () => { selectionItemProvider1.Select(); }, // Nothing changes, is already selected () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #7"); Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #8"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #9"); }, () => { selectionItemProvider1.RemoveFromSelection(); }, // Nothing happens, Remove does nothing. () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #10"); Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #11"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #12"); }, () => { selectionItemProvider2.AddToSelection(); }, // Doesn't throw exception () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #13"); Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #14"); Assert.IsTrue(selectionItemProvider2.IsSelected, "IsSelected #15"); }, () => { selectionItemProvider0.Select(); }, () => { Assert.IsTrue(selectionItemProvider0.IsSelected, "IsSelected #16"); Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #17"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #18"); }); }
public void VerifyUIANameBehavior() { NumberBox numberBox = null; TextBox textBox = null; RunOnUIThread.Execute(() => { numberBox = new NumberBox(); Content = numberBox; Content.UpdateLayout(); textBox = TestPage.FindVisualChildrenByType <TextBox>(numberBox)[0]; Verify.IsNotNull(textBox); numberBox.Header = "Some header"; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { VerifyUIAName("Some header"); numberBox.Header = new Button(); AutomationProperties.SetName(numberBox, "Some UIA name"); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { VerifyUIAName("Some UIA name"); numberBox.Header = new Button(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { VerifyUIAName("Some UIA name"); numberBox.Minimum = 0; numberBox.Maximum = 10; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { VerifyUIAName("Some UIA name Minimum0 Maximum10"); numberBox.Minimum = 50; numberBox.Maximum = 100; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { VerifyUIAName("Some UIA name Minimum50 Maximum100"); }); void VerifyUIAName(string value) { Verify.AreEqual(value, FrameworkElementAutomationPeer.CreatePeerForElement(textBox).GetName()); } }
/// <summary> /// Given the TabItem in the list of Items, we will set that item as the /// currently selected item, and un-select the rest of the items. /// </summary> /// <param name="oldItem">Previous TabItem that was unselected.</param> /// <param name="newItem">New TabItem to set as the SelectedItem.</param> private void SelectItem(TabItem oldItem, TabItem newItem) { if (newItem == null) { ContentPresenter contentHost = GetContentHost(TabStripPlacement); if (contentHost != null) { contentHost.Content = null; } SetValue(SelectedContentProperty, null); } foreach (object item in Items) { TabItem tabItem = item as TabItem; if (tabItem == null) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, System.Windows.Controls.Properties.Resources.TabControl_InvalidChild, item.GetType().ToString())); } if (tabItem != newItem && tabItem.IsSelected) { tabItem.IsSelected = false; } else if (tabItem == newItem) { tabItem.IsSelected = true; SetValue(SelectedContentProperty, tabItem.Content); } } // Notify automation peers of selection change if (newItem != null && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected)) { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(newItem); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } if (oldItem != null && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(oldItem); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } // Fire SelectionChanged Event SelectionChangedEventHandler handler = SelectionChanged; if (handler != null) { SelectionChangedEventArgs args = new SelectionChangedEventArgs( (oldItem == null ? new List <TabItem> { } : new List <TabItem> { oldItem }), (newItem == null ? new List <TabItem> { } : new List <TabItem> { newItem })); handler(this, args); } }
public override void GetAutomationControlType() { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(CreateConcreteFrameworkElement()); Assert.AreEqual(AutomationControlType.Window, peer.GetAutomationControlType(), "GetAutomationControlType"); }
public override void GetClassName() { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(CreateConcreteFrameworkElement()); Assert.AreEqual("Popup", peer.GetClassName(), "GetClassName"); }
public override void IsOffScreen_Event1() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } Canvas parent0 = new Canvas(); parent0.Height = 100; parent0.Width = 100; StackPanel parent1 = new StackPanel(); parent1.Height = 200; parent1.Width = 100; parent0.Children.Add(parent1); FrameworkElement fe = CreateConcreteFrameworkElement(); fe.SetValue(Canvas.WidthProperty, (double)150); fe.SetValue(Canvas.HeightProperty, (double)230); parent1.Children.Add(fe); AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(fe); AutomationPropertyEventTuple tuple = null; CreateAsyncTest(parent0, () => { EventsManager.Instance.Reset(); parent0.Visibility = Visibility.Visible; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #4"); }, () => { // Testing when our parent is not Visible EventsManager.Instance.Reset(); parent0.Visibility = Visibility.Collapsed; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #1"); }, () => { EventsManager.Instance.Reset(); parent1.Visibility = Visibility.Collapsed; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #4"); }, () => { EventsManager.Instance.Reset(); parent0.Visibility = Visibility.Visible; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #5"); }, () => { EventsManager.Instance.Reset(); parent1.Visibility = Visibility.Visible; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #7"); }); }
public override void IsOffScreen_Event() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } Popup fe = CreateConcreteFrameworkElement() as Popup; fe.SetValue(Canvas.TopProperty, (double)10); fe.SetValue(Canvas.LeftProperty, (double)30); fe.SetValue(Canvas.WidthProperty, (double)150); fe.SetValue(Canvas.HeightProperty, (double)230); AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(fe); AutomationPropertyEventTuple tuple = null; CreateAsyncTest(fe, () => { EventsManager.Instance.Reset(); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.BoundingRectangleProperty); Assert.IsNull(tuple, "#0"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #0"); }, () => { EventsManager.Instance.Reset(); fe.Visibility = Visibility.Visible; }, () => { EventsManager.Instance.Reset(); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.BoundingRectangleProperty); Assert.IsNull(tuple, "#1"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #1"); }, () => { EventsManager.Instance.Reset(); fe.Visibility = Visibility.Collapsed; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.BoundingRectangleProperty); Assert.IsNotNull(tuple, "#2"); Rect newValue = (Rect)tuple.NewValue; Assert.AreEqual(0, newValue.X, "#4"); Assert.AreEqual(0, newValue.Y, "#5"); Assert.AreEqual(0, newValue.Width, "#6"); Assert.AreEqual(0, newValue.Height, "#7"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNull(tuple, "IsOffscreen #2"); }, () => { EventsManager.Instance.Reset(); fe.Visibility = Visibility.Visible; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.BoundingRectangleProperty); Assert.IsNull(tuple, "#8"); }, () => { EventsManager.Instance.Reset(); fe.IsOpen = true; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.BoundingRectangleProperty); Assert.IsNotNull(tuple, "#9"); Rect newValue = (Rect)tuple.NewValue; Rect oldValue = (Rect)tuple.OldValue; Assert.AreNotEqual(newValue.X, oldValue.X, "#10"); Assert.AreNotEqual(newValue.Y, oldValue.Y, "#11"); Assert.AreNotEqual(newValue.Width, oldValue.Width, "#12"); Assert.AreNotEqual(newValue.Height, oldValue.Height, "#13"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNotNull(tuple, "IsOffscreen #3"); Assert.IsFalse((bool)tuple.NewValue, "IsOffscreen #4"); Assert.IsTrue((bool)tuple.OldValue, "IsOffscreen #5"); }, () => { EventsManager.Instance.Reset(); fe.IsOpen = false; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.BoundingRectangleProperty); Assert.IsNotNull(tuple, "#14"); Rect newValue = (Rect)tuple.NewValue; Rect oldValue = (Rect)tuple.OldValue; Assert.AreNotEqual(newValue.X, oldValue.X, "#15"); Assert.AreNotEqual(newValue.Y, oldValue.Y, "#16"); Assert.AreNotEqual(newValue.Width, oldValue.Width, "#17"); Assert.AreNotEqual(newValue.Height, oldValue.Height, "#18"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationElementIdentifiers.IsOffscreenProperty); Assert.IsNotNull(tuple, "IsOffscreen #6"); Assert.IsTrue((bool)tuple.NewValue, "IsOffscreen #7"); Assert.IsFalse((bool)tuple.OldValue, "IsOffscreen #8"); }); }
public void ValueProvider_Events() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } TextBox textbox = CreateConcreteFrameworkElement() as TextBox; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(textbox); AutomationPropertyEventTuple tuple = null; CreateAsyncTest(textbox, // IsReadOnly () => { EventsManager.Instance.Reset(); textbox.IsReadOnly = true; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, ValuePatternIdentifiers.IsReadOnlyProperty); Assert.IsNotNull(tuple, "GetAutomationEventFrom #0"); Assert.IsTrue((bool)tuple.NewValue, "GetAutomationEventFrom.NewValue #0"); Assert.IsFalse((bool)tuple.OldValue, "GetAutomationEventFrom.NewValue #0"); }, () => { EventsManager.Instance.Reset(); textbox.IsEnabled = false; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, ValuePatternIdentifiers.IsReadOnlyProperty); Assert.IsNull(tuple, "GetAutomationEventFrom #1"); }, () => { EventsManager.Instance.Reset(); textbox.IsReadOnly = false; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, ValuePatternIdentifiers.IsReadOnlyProperty); Assert.IsNotNull(tuple, "GetAutomationEventFrom #2"); Assert.IsFalse((bool)tuple.NewValue, "GetAutomationEventFrom.NewValue #2"); Assert.IsTrue((bool)tuple.OldValue, "GetAutomationEventFrom.NewValue #2"); }, () => { EventsManager.Instance.Reset(); textbox.IsEnabled = true; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, ValuePatternIdentifiers.IsReadOnlyProperty); Assert.IsNull(tuple, "GetAutomationEventFrom #3"); }, // Value () => { textbox.Text = string.Empty; EventsManager.Instance.Reset(); textbox.Text = "hello world"; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, ValuePatternIdentifiers.ValueProperty); Assert.IsNotNull(tuple, "GetAutomationEventFrom #4"); Assert.AreEqual("hello world", tuple.NewValue, "GetAutomationEventFrom.NewValue #4"); Assert.AreEqual(string.Empty, tuple.OldValue, "GetAutomationEventFrom.NewValue #4"); }, () => { EventsManager.Instance.Reset(); textbox.Text = string.Empty; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, ValuePatternIdentifiers.ValueProperty); Assert.IsNotNull(tuple, "GetAutomationEventFrom #5"); Assert.AreEqual(string.Empty, tuple.NewValue, "GetAutomationEventFrom.NewValue #5"); Assert.AreEqual("hello world", tuple.OldValue, "GetAutomationEventFrom.NewValue #5"); }); }
private void OnLoaded(object sender, RoutedEventArgs e) { var automationPeer = new FrameworkElementAutomationPeer(this); automationPeer.RaiseAutomationEvent(AutomationEvents.AsyncContentLoaded); }
internal void ProcessSort() { // if we can sort: // - DataConnection.AllowSort is true, and // - AllowUserToSortColumns and CanSort are true, and // - OwningColumn is bound, and // - SortDescriptionsCollection exists, and // - the column's data type is comparable // then try to sort if (this.OwningColumn != null && this.OwningGrid != null && this.OwningGrid.EditingRow == null && this.OwningColumn != this.OwningGrid.ColumnsInternal.FillerColumn && this.OwningGrid.DataConnection.AllowSort && this.OwningGrid.CanUserSortColumns && this.OwningColumn.CanUserSort && this.OwningGrid.DataConnection.SortDescriptions != null) { DataGrid owningGrid = this.OwningGrid; ListSortDirection newSortDirection; SortDescription newSort; bool ctrl; bool shift; KeyboardHelper.GetMetaKeyState(out ctrl, out shift); SortDescription?sort = this.OwningColumn.GetSortDescription(); ICollectionView collectionView = owningGrid.DataConnection.CollectionView; Debug.Assert(collectionView != null); using (collectionView.DeferRefresh()) { // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0) { if (collectionView.CanGroup && collectionView.GroupDescriptions != null) { // Make sure we sort by the GroupDescriptions first for (int i = 0; i < collectionView.GroupDescriptions.Count; i++) { PropertyGroupDescription groupDescription = collectionView.GroupDescriptions[i] as PropertyGroupDescription; if (groupDescription != null && collectionView.SortDescriptions.Count <= i || collectionView.SortDescriptions[i].PropertyName != groupDescription.PropertyName) { collectionView.SortDescriptions.Insert(Math.Min(i, collectionView.SortDescriptions.Count), new SortDescription(groupDescription.PropertyName, ListSortDirection.Ascending)); } } while (collectionView.SortDescriptions.Count > collectionView.GroupDescriptions.Count) { collectionView.SortDescriptions.RemoveAt(collectionView.GroupDescriptions.Count); } } else if (!shift) { owningGrid.DataConnection.SortDescriptions.Clear(); } } if (sort.HasValue) { // swap direction switch (sort.Value.Direction) { case ListSortDirection.Ascending: newSortDirection = ListSortDirection.Descending; break; default: newSortDirection = ListSortDirection.Ascending; break; } newSort = new SortDescription(sort.Value.PropertyName, newSortDirection); // changing direction should not affect sort order, so we replace this column's // sort description instead of just adding it to the end of the collection int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort.Value); if (oldIndex >= 0) { owningGrid.DataConnection.SortDescriptions.Remove(sort.Value); owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort); } else { owningGrid.DataConnection.SortDescriptions.Add(newSort); } } else { // start new sort newSortDirection = ListSortDirection.Ascending; string propertyName = this.OwningColumn.GetSortPropertyName(); // no-opt if we couldn't find a property to sort on if (string.IsNullOrEmpty(propertyName)) { return; } newSort = new SortDescription(propertyName, newSortDirection); owningGrid.DataConnection.SortDescriptions.Add(newSort); } } // We've completed the sort, so send the Invoked event for the column header's automation peer if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } } } }
public void GetChildrenSelection() { TabControl tabControl = new TabControl(); TabItem tabItem0 = new TabItem() { Header = "TabItem0", Content = new TextBlock() { Text = "Content0" } }; TabItem tabItem1 = new TabItem() { Header = "TabItem1", Content = new TextBlock() { Text = "Content1" } }; TabItem tabItem2 = new TabItem() { Header = "TabItem2", Content = new TextBlock() { Text = "Content2" } }; tabControl.Items.Add(tabItem0); tabControl.Items.Add(tabItem1); tabControl.Items.Add(tabItem2); AutomationPeer tabPeer = null; AutomationPeer tabItemPeer0 = null; AutomationPeer tabItemPeer1 = null; AutomationPeer tabItemPeer2 = null; CreateAsyncTest(tabControl, () => { tabPeer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); tabItemPeer0 = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem0); tabItemPeer1 = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem1); tabItemPeer2 = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem2); Assert.IsNotNull(tabPeer, "#0"); Assert.IsNotNull(tabPeer.GetChildren(), "#1"); Assert.AreEqual(3, tabPeer.GetChildren().Count, "#2"); Assert.IsNotNull(tabItemPeer0, "#3"); Assert.IsNotNull(tabItemPeer1, "#4"); Assert.IsNotNull(tabItemPeer2, "#5"); }, () => tabControl.SelectedItem = tabItem0, () => { List <AutomationPeer> children = tabItemPeer0.GetChildren(); Assert.IsNotNull(children, "#6"); Assert.AreEqual(2, children.Count, "#7"); Assert.AreEqual("TabItem0", children [0].GetName(), "#8"); Assert.AreEqual("Content0", children [1].GetName(), "#9"); children = tabItemPeer1.GetChildren(); Assert.IsNotNull(children, "#10"); Assert.AreEqual(1, children.Count, "#11"); Assert.AreEqual("TabItem1", children [0].GetName(), "#12"); children = tabItemPeer2.GetChildren(); Assert.IsNotNull(children, "#13"); Assert.AreEqual(1, children.Count, "#14"); Assert.AreEqual("TabItem2", children [0].GetName(), "#15"); }, () => tabControl.SelectedItem = tabItem1, () => { List <AutomationPeer> children = tabItemPeer0.GetChildren(); Assert.IsNotNull(children, "#16"); Assert.AreEqual(2, children.Count, "#17"); children = tabItemPeer1.GetChildren(); Assert.IsNotNull(children, "#18"); Assert.AreEqual(3, children.Count, "#19"); children = tabItemPeer2.GetChildren(); Assert.IsNotNull(children, "#20"); Assert.AreEqual(1, children.Count, "#21"); }, () => tabControl.SelectedItem = tabItem2, () => { List <AutomationPeer> children = tabItemPeer0.GetChildren(); Assert.IsNotNull(children, "#22"); Assert.AreEqual(2, children.Count, "#23"); children = tabItemPeer1.GetChildren(); Assert.IsNotNull(children, "#24"); Assert.AreEqual(2, children.Count, "#25"); children = tabItemPeer2.GetChildren(); Assert.IsNotNull(children, "#26"); Assert.AreEqual(3, children.Count, "#27"); }); }
protected override void DoImpl() { var element = GetFrameworkElement(); var selector = element as Selector; if (selector == null) { return; } var item = selector.Items[IndexOfItemToSelect]; var identifier = new AutomationIdentifier { DisplayedText = item.ToString() }; var listBoxItem = AutomationElementFinder.FindElement(identifier); if (listBoxItem == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the list box item element : {0}", identifier.ToIdOrName())); return; } var button = AutomationElementFinder.FindElementsChildByType <Button>(listBoxItem); if (button != null) // Workaround for nasty lists that use buttons instead of the list select method { // automate the invoke var buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(button); var pattern = buttonPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; if (pattern == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the invoke pattern : {0}", identifier.ToIdOrName())); return; } try { pattern.Invoke(); } catch (Exception exception) { SendExceptionFailedResult(exception); } } else { // automate the select var listBoxPeer = FrameworkElementAutomationPeer.CreatePeerForElement(listBoxItem); var pattern = listBoxPeer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; if (pattern == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the select pattern : {0}", identifier.ToIdOrName())); return; } try { pattern.Select(); } catch (Exception exception) { SendExceptionFailedResult(exception); } } SendSuccessResult(); }
public override void ContentTest() { Assert.IsTrue(IsContentPropertyElement(), "ItemAutomation is ContentElement."); TabControl tabControl = new TabControl(); TabItem tabItem = new TabItem(); TabItem tabItem1 = new TabItem() { Content = new TextBlock() { Text = "TextBlock" } }; AutomationPeer peer = null; StackPanel stackPanel = null; tabControl.Items.Add(tabItem); tabControl.Items.Add(tabItem1); CreateAsyncTest(tabControl, () => { AutomationPeer tabPeer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); List <AutomationPeer> children = tabPeer.GetChildren(); Assert.IsNotNull(children, "GetChildren #0"); Assert.AreEqual(2, children.Count, "GetChildren.Count #0"); peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem); Assert.IsNotNull(peer, "#0"); }, () => tabItem.IsSelected = true, () => { stackPanel = new StackPanel(); stackPanel.Children.Add(new TextBlock() { Text = "Text0" }); stackPanel.Children.Add(new TextBlock() { Text = "Text1" }); Assert.IsNull(peer.GetChildren(), "GetChildren #1"); }, () => tabItem.Content = stackPanel, () => { List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #2"); Assert.AreEqual(2, children.Count, "GetChildren.Count #2"); }, () => stackPanel.Children.Add(new TextBlock() { Text = "Text2" }), () => { List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #3"); Assert.AreEqual(3, children.Count, "GetChildren.Count #3"); }, () => tabItem1.IsSelected = true, () => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem1); Assert.IsNotNull(peer, "#1"); List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #4"); Assert.AreEqual(1, children.Count, "GetChildren.Count #4"); }); }
public virtual void ISelectionProvider_Events() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } Selector selector = CreateConcreteFrameworkElement() as Selector; selector.Width = 300; selector.Height = 400; selector.Items.Add(new TextBlock() { Text = "Item0" }); selector.Items.Add(new TextBlock() { Text = "Item1" }); AutomationPeer peer = null; AutomationPeer childPeer = null; IRawElementProviderSimple[] selection = null; AutomationPropertyEventTuple propertyTuple = null; ISelectionProvider selectionProvider = null; CreateAsyncTest(selector, () => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(selector); selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "Selection Provider"); Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple #0"); Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #0"); selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #0"); }, () => { EventsManager.Instance.Reset(); selector.SelectedIndex = 1; }, () => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #1"); Assert.AreEqual(1, selection.Length, "GetSelection #2"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #0"); Assert.IsNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #0"); Assert.IsNotNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #0"); childPeer = new PeerFromProvider().GetPeerFromProvider(selection [0]); }, () => { EventsManager.Instance.Reset(); selector.Items.Add(new TextBlock() { Text = "Item1" }); selector.SelectedIndex = 0; }, () => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #3"); Assert.AreEqual(1, selection.Length, "GetSelection #4"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #1"); Assert.IsNotNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #1"); Assert.IsNotNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #1"); Assert.AreNotEqual(selection [0], childPeer, "GetSelection #5"); }, () => { EventsManager.Instance.Reset(); selector.SelectedIndex = -1; }, () => { selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #6"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #2"); Assert.IsNotNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #2"); Assert.IsNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #2"); }); }
public void ISelectionItemProvider_Events() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } TabControl tabControl = new TabControl(); TabItem item0 = new TabItem() { Header = "Item0", Content = new TextBlock() { Text = "Item 0" } }; TabItem item1 = new TabItem() { Header = "Item1", Content = new TextBlock() { Text = "Item 1" } }; TabItem item2 = new TabItem() { Header = "Item2", Content = new TextBlock() { Text = "Item 2" } }; tabControl.Items.Add(item0); tabControl.Items.Add(item1); tabControl.Items.Add(item2); item0.IsSelected = true; AutomationPeer peer0 = null; AutomationPeer peer1 = null; AutomationPeer peer2 = null; ISelectionItemProvider selectionItemProvider0 = null; ISelectionItemProvider selectionItemProvider1 = null; ISelectionItemProvider selectionItemProvider2 = null; AutomationPropertyEventTuple propertyTuple = null; CreateAsyncTest(tabControl, () => { AutomationPeer tabControlPeer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); List <AutomationPeer> children = tabControlPeer.GetChildren(); Assert.IsNotNull(children, "GetChildren #0"); peer0 = children [0]; peer1 = children [1]; peer2 = children [2]; selectionItemProvider0 = peer0.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider0, "SelectionItem Provider #1"); selectionItemProvider1 = peer1.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider1, "SelectionItem Provider #2"); selectionItemProvider2 = peer2.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider2, "SelectionItem Provider #3"); selectionItemProvider1 = peer1.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider1, "SelectionItem Provider #0"); selectionItemProvider2 = peer2.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItemProvider2, "SelectionItem Provider #1"); Assert.IsTrue(selectionItemProvider0.IsSelected, "IsSelected #1"); Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #2"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #3"); EventsManager.Instance.Reset(); selectionItemProvider0.Select(); // Nothing really changes }, () => { EventsManager.Instance.Reset(); selectionItemProvider1.AddToSelection(); }, () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #4"); Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #5"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #6"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer0, SelectionItemPatternIdentifiers.IsSelectedProperty); Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #0"); Assert.IsTrue((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #0"); Assert.IsFalse((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #0"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty); Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #1"); Assert.IsFalse((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #1"); Assert.IsTrue((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #1"); }, () => { EventsManager.Instance.Reset(); selectionItemProvider1.Select(); // Nothing really changes }, () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #7"); Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #8"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #9"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty); Assert.IsNull(propertyTuple, "GetPropertyAutomationEventFrom #2"); }, () => { EventsManager.Instance.Reset(); selectionItemProvider1.RemoveFromSelection(); // Nothing really changes }, () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #10"); Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #11"); Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #12"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty); Assert.IsNull(propertyTuple, "GetPropertyAutomationEventFrom #3"); }, () => { EventsManager.Instance.Reset(); selectionItemProvider2.Select(); }, () => { Assert.IsFalse(selectionItemProvider0.IsSelected, "IsSelected #13"); Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #14"); Assert.IsTrue(selectionItemProvider2.IsSelected, "IsSelected #15"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty); Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #4"); Assert.IsTrue((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #4"); Assert.IsFalse((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #4"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer2, SelectionItemPatternIdentifiers.IsSelectedProperty); Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #5"); Assert.IsFalse((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #5"); Assert.IsTrue((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #5"); }); }
/// <summary> /// Change whether a TreeViewItem is selected. /// </summary> /// <param name="itemOrContainer"> /// Item whose selection is changing. /// </param> /// <param name="container"> /// Container of the item whose selection is changing. /// </param> /// <param name="selected"> /// A value indicating whether the TreeViewItem is selected. /// </param> internal void ChangeSelection(object itemOrContainer, TreeViewItem container, bool selected) { // Ignore any change notifications if we're alread in the middle of // changing the selection if (IsSelectionChangeActive) { return; } object oldValue = null; object newValue = null; bool raiseSelectionChanged = false; TreeViewItem element = SelectedContainer; // Start changing the selection IsSelectionChangeActive = true; try { if (selected && container != SelectedContainer) { // Unselect the old value oldValue = SelectedItem; if (SelectedContainer != null) { SelectedContainer.IsSelected = false; SelectedContainer.UpdateContainsSelection(false); } // Select the new value newValue = itemOrContainer; SelectedContainer = container; SelectedContainer.UpdateContainsSelection(true); SelectedItem = itemOrContainer; UpdateSelectedValue(itemOrContainer); raiseSelectionChanged = true; // Scroll the selected item into view. We only want to // scroll the header into view, if possible, because an // expanded TreeViewItem contains all of its child items // as well. ItemsControlHelper.ScrollIntoView(container.HeaderElement ?? container); } else if (!selected && container == SelectedContainer) { // Unselect the old value SelectedContainer.UpdateContainsSelection(false); SelectedContainer = null; SelectedItem = null; SelectedValue = null; oldValue = itemOrContainer; raiseSelectionChanged = true; } container.IsSelected = selected; } finally { // Finish changing the selection IsSelectionChangeActive = false; } // Notify when the selection changes if (raiseSelectionChanged) { if (SelectedContainer != null && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected)) { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(SelectedContainer); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } if (element != null && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(element); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } OnSelectedItemChanged(new RoutedPropertyChangedEventArgs <object>(oldValue, newValue)); } }
private CalendarSelectableCellnfoAutomationPeer GetOrCreatePeerFromDateTime(DateTime date) { CalendarSelectableCellnfoAutomationPeer peer = this.childrenCache.OfType <CalendarSelectableCellnfoAutomationPeer>().Where(x => x.CellModel.Date == date).FirstOrDefault(); if (peer == null && this.CalendarOwner.Model.CalendarCells != null) { CalendarCellModel model = this.CalendarOwner.Model.CalendarCells.Where(cell => cell.Date == date).FirstOrDefault(); if (model != null) { CalendarViewHostAutomationPeer hostPeer = (CalendarViewHostAutomationPeer)FrameworkElementAutomationPeer.FromElement(this.CalendarOwner.calendarViewHost); peer = new CalendarSelectableCellnfoAutomationPeer(hostPeer, model); this.childrenCache.Add(peer); } } return(peer); }
// We use UIA AutopmationEvents to send notifications about Window Visisbility changes, // since there are no direct events for this exposed directly in UIA / Mita. // Also, here isn't a custom AutomationEvent type, so use an existing event type - AsyncContentLoaded. // The InteractionTest expects it to fire in a specific pattern and hence extracts its own meaning // from each firing of the event. private void XamlWindow_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e) { var automationPeer = FrameworkElementAutomationPeer.FromElement(this); automationPeer.RaiseAutomationEvent(AutomationEvents.AsyncContentLoaded); }
// IFrameworkElement protected override void OnApplyTemplate() { // Uno Doc: Added to dispose event handlers _eventSubscriptions.Disposable = null; var registrations = new CompositeDisposable(); if (GetTemplateChild <Control>(c_expanderHeader) is ToggleButton toggleButton) { // We will do 2 things with the toggle button's peer: // 1. Set the events source of the toggle button peer to // the expander's automation peer. This is is because we // don't want to announce the toggle button's on/off property // changes, but the expander's expander/collapse property changes // (or on the events source that's set, if it's set) and // // 2. Set the expander's automation properties name to the // toggleButton's in case the expander doesn't have one. This just follows // what WPF does. if (FrameworkElementAutomationPeer.FromElement(toggleButton) is AutomationPeer toggleButtonPeer) { // 1. Set the events source of the toggle button peer to the expander's. if (FrameworkElementAutomationPeer.FromElement(this) is AutomationPeer expanderPeer) { // Uno Doc: EventSource is not implemented in the Uno Platform //var expanderEventsSource = expanderPeer.EventsSource != null ? // expanderPeer.EventsSource : // expanderPeer; //toggleButtonPeer.EventsSource = expanderEventsSource; } // 2. If the expander doesn't have any AutomationProperties.Name set, // we will try setting one based on the header. This is how // WPF's expanders work. if (string.IsNullOrEmpty(AutomationProperties.GetName(this)) && !string.IsNullOrEmpty(toggleButtonPeer.GetName())) { // Uno Doc: The equivalent '.GetName()' substituted for '.GetNameCore()' in WinUI AutomationProperties.SetName(this, toggleButtonPeer.GetName()); } } } if (GetTemplateChild <Border>(c_expanderContentClip) is Border expanderContentClip) { // TODO Uno specific: The Composition clipping APIs are currently unsupported, // so UIElement.Clip a layout slot for the Expander content when the // SizeChanged event is fired. #if HAS_UNO expanderContentClip.SizeChanged += OnContentClipSizeChanged; registrations.Add(() => expanderContentClip.SizeChanged -= OnContentClipSizeChanged); #else var visual = ElementCompositionPreview.GetElementVisual(expanderContentClip); visual.Clip = visual.Compositor.CreateInsetClip(); #endif } if (GetTemplateChild <Border>(c_expanderContent) is Border expanderContent) { expanderContent.SizeChanged += OnContentSizeChanged; registrations.Add(() => expanderContent.SizeChanged -= OnContentSizeChanged); } UpdateExpandState(false); UpdateExpandDirection(false); // Uno Doc: Added to dispose event handlers _eventSubscriptions.Disposable = registrations; }
/// <inheritdoc /> protected override IList <AutomationPeer> GetChildrenCore() { List <AutomationPeer> children = new List <AutomationPeer>(); List <AutomationPeer> dataGridContentLayerPanelChildren = new List <AutomationPeer>(); var dataGridCellsPanelAutomationPeerChildren = base.GetChildrenCore(); DataGridContentLayerPanelAutomationPeer dataGridContentLayerPanelPeer = null; if (dataGridCellsPanelAutomationPeerChildren.Count > 0) { dataGridContentLayerPanelPeer = dataGridCellsPanelAutomationPeerChildren.Where(a => a.GetName() == nameof(DataGridContentLayerPanel)).FirstOrDefault() as DataGridContentLayerPanelAutomationPeer; if (dataGridContentLayerPanelPeer != null) { dataGridContentLayerPanelChildren = dataGridContentLayerPanelPeer.GetChildren().ToList(); } } if (this.DataGridCellsPanel != null) { var dataGridPeers = FrameworkElementAutomationPeer.FromElement(this.dataGrid) as RadDataGridAutomationPeer; if (dataGridPeers != null && dataGridPeers.childrenCache != null) { var rows = this.dataGrid.Model.RowPool.GetDisplayedItems(); foreach (var row in rows) { var cellsForRow = this.dataGrid.Model.CellsController.GetCellsForRow(row.Slot); if (cellsForRow.Count() > 0) { foreach (var cell in cellsForRow) { DataGridCellInfoAutomationPeer peer = dataGridPeers.childrenCache.Where(a => a.Row == row.Slot && a.Column == cell.Column.ItemInfo.Slot).FirstOrDefault(); if (peer == null) { peer = new DataGridCellInfoAutomationPeer(row.Slot, cell.Column.ItemInfo.Slot, dataGridPeers, row.Item); dataGridPeers.childrenCache.Add(peer); } var cellContainer = cell.Container as TextBlock; if (cellContainer != null) { var tbPeer = FrameworkElementAutomationPeer.FromElement(cellContainer) as TextBlockAutomationPeer; if (tbPeer != null) { peer.ChildTextBlockPeer = tbPeer; } } children.Add(peer); } } } } } if (dataGridContentLayerPanelChildren.Count > 0) { dataGridContentLayerPanelChildren.RemoveAll(a => a.GetClassName() == nameof(Windows.UI.Xaml.Controls.TextBlock)); children.AddRange(dataGridContentLayerPanelChildren); } return(children); }
public override void GetName() { base.GetName(); // LAMESPEC: MSDN: A string that contains the name, minus the accelerator key. ButtonBase button = CreateConcreteFrameworkElement() as ButtonBase; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(button); Assert.IsNotNull(peer, "IsNotNull #0"); Assert.AreEqual(string.Empty, peer.GetName(), "GetName #0"); button.Content = "Hello I'm button"; Assert.AreEqual("Hello I'm button", peer.GetName(), "GetName #1"); button.Content = "Hello I'm &button"; Assert.AreEqual("Hello I'm &button", peer.GetName(), "GetName #2"); button.Content = "Hello I'm &&button"; Assert.AreEqual("Hello I'm &&button", peer.GetName(), "GetName #3"); button.Content = null; Assert.AreEqual(string.Empty, peer.GetName(), "GetName #4"); TextBox textbox = new TextBox(); textbox.Text = "I'm textbox"; button.Content = textbox; Assert.AreEqual(string.Empty, peer.GetName(), "GetName #5"); TextBlock textblock = new TextBlock(); textblock.Text = "I'm textblock"; button.Content = textblock; Assert.AreEqual("I'm textblock", peer.GetName(), "GetName #6"); button.Content = "I'm a button"; Assert.AreEqual("I'm a button", peer.GetName(), "GetName #7"); // Now usin a stack panel with a textblock StackPanel panel = new StackPanel(); panel.Children.Add(new TextBlock() { Text = "Textblock in Stackpanel1" }); button.Content = panel; Assert.AreEqual(string.Empty, peer.GetName(), "GetName #8"); panel.Children.Add(new TextBlock() { Text = "Textblock in Stackpanel2" }); Assert.AreEqual(string.Empty, peer.GetName(), "GetName #9"); button.Content = "What's up?"; Assert.AreEqual("What's up?", peer.GetName(), "GetName #10"); }
private async void NonAccessibleSubmitOnClick(object sender, RoutedEventArgs e) { var error = false; var nameAutomationPeer = FrameworkElementAutomationPeer.FromElement(this.NameError); var ageAutomationPeer = FrameworkElementAutomationPeer.FromElement(this.AgeError); if (string.IsNullOrWhiteSpace(NameBox.Text)) { if (NameError.Visibility != Visibility.Visible) { NameError.Visibility = Visibility.Visible; if (nameAutomationPeer != null) { nameAutomationPeer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged); } } error = true; } else { NameError.Visibility = Visibility.Collapsed; } if (string.IsNullOrWhiteSpace(AgeBox.Text)) { if (AgeError.Visibility != Visibility.Visible) { AgeError.Visibility = Visibility.Visible; if (ageAutomationPeer != null) { ageAutomationPeer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged); } } error = true; } else { int age; if (!int.TryParse(AgeBox.Text, out age)) { if (AgeError.Visibility != Visibility.Visible) { AgeError.Visibility = Visibility.Visible; if (ageAutomationPeer != null) { ageAutomationPeer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged); } } error = true; } else { AgeError.Visibility = Visibility.Collapsed; } } if (error) { return; } var dialog = new MessageDialog("Looks good!"); await dialog.ShowAsync(); }
/// <summary> /// Update <see cref="AutomationProperties.NameProperty"/> on <paramref name="element"/> /// and all its parents as far up as needed and only when the name is generated. This must be called /// when anything influencing generated names has changed in <paramref name="element"/> or somewhere in its subtree. /// </summary> /// <param name="element"></param> private static void UpdateGeneratedNameHereAndUp(UIElement element) { var peer = FrameworkElementAutomationPeer.FromElement(element); UpdateGeneratedNameHereAndUp(peer); }
/// <summary> /// IsDropDownOpenProperty property changed handler. /// </summary> /// <param name="d">AutoCompleteTextBox that changed its IsDropDownOpen.</param> /// <param name="e">Event arguments.</param> private static void OnIsDropDownOpenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; // Ignore the change if requested if (source.IgnorePropertyChange) { source.IgnorePropertyChange = false; return; } bool oldValue = (bool)e.OldValue; bool newValue = (bool)e.NewValue; bool delayedClosingVisual = source.PopupClosedVisualState; RoutedPropertyChangingEventArgs <bool> args = new RoutedPropertyChangingEventArgs <bool>(e.Property, oldValue, newValue, true); AutoCompleteBoxAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(source) as AutoCompleteBoxAutomationPeer; if (peer != null) { peer.RaiseExpandCollapseAutomationEvent(oldValue, newValue); } if (newValue) { // Opening source.OnDropDownOpening(args); // Opened if (!args.Cancel) { source.OpenDropDown(oldValue, newValue); } } else { // Closing source.OnDropDownClosing(args); if (source.View == null || source.View.Count == 0) { delayedClosingVisual = false; } // Immediately close the drop down window: // When a popup closed visual state is present, the code path is // slightly different and the actual call to CloseDropDown will // be called only after the visual state's transition is done if (!args.Cancel && !delayedClosingVisual) { source.CloseDropDown(oldValue, newValue); } } // If canceled, revert the value change if (args.Cancel) { source.IgnorePropertyChange = true; source.SetValue(e.Property, oldValue); } // Closing call when visual states are in use if (delayedClosingVisual) { source.UpdateVisualState(true); } }