public override void ContentTest() { Assert.IsTrue(IsContentPropertyElement(), "TextBlock ContentElement."); bool textBlockLoaded = false; TextBlock textBlock = CreateConcreteFrameworkElement() as TextBlock; textBlock.Loaded += (o, e) => textBlockLoaded = true; TestPanel.Children.Add(textBlock); EnqueueConditional(() => textBlockLoaded, "TextBlock #0"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(textBlock); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNull(peer.GetChildren(), "GetChildren #0"); textBlock.Text = "Hello world!"; }); // We add the text Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(textBlock); Assert.IsNull(peer.GetChildren(), "GetChildren #1"); // Remove text textBlock.Text = string.Empty; Assert.IsNull(peer.GetChildren(), "GetChildren #2"); }); EnqueueTestComplete(); }
public override void ContentTest() { TabControl tabControl = CreateConcreteFrameworkElement() as TabControl; AutomationPeer peer = null; CreateAsyncTest(tabControl, () => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNull(peer.GetChildren(), "GetChildren #0"); tabControl.Items.Add(new TabItem()); }, () => { List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #1"); Assert.AreEqual(1, children.Count, "GetChildren.Count #1"); }, () => tabControl.Items.Add(new TabItem()), () => { List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #2"); Assert.AreEqual(2, children.Count, "GetChildren.Count #2"); }); }
public override void ContentTest() { ButtonBase button = (ButtonBase)CreateConcreteFrameworkElement(); Assert.IsTrue(IsContentPropertyElement(), "ButtonElement ContentElement."); bool buttonLoaded = false; button.Loaded += (o, e) => buttonLoaded = true; TestPanel.Children.Add(button); // StackPanel and two TextBlocks bool stackPanelLoaded = false; StackPanel stackPanel = new StackPanel(); stackPanel.Children.Add(new TextBlock() { Text = "Text0" }); stackPanel.Children.Add(new TextBlock() { Text = "Text1" }); stackPanel.Loaded += (o, e) => stackPanelLoaded = true; int INITIAL_CHILDREN_COUNT = 2; EnqueueConditional(() => buttonLoaded, "ButtonLoaded #0"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(button); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNotNull(peer.GetChildren(), "GetChildren#0"); Assert.AreEqual(INITIAL_CHILDREN_COUNT, peer.GetChildren().Count, "GetChildren #0, count"); Assert.AreEqual(typeof(TextBlockAutomationPeer), peer.GetChildren() [0].GetType(), "GetChildren #0, type#1"); Assert.AreEqual(typeof(TextBlockAutomationPeer), peer.GetChildren() [1].GetType(), "GetChildren #0, type#2"); button.Content = stackPanel; }); EnqueueConditional(() => buttonLoaded && stackPanelLoaded, "ButtonLoaded #1"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(button); Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); Assert.AreEqual(INITIAL_CHILDREN_COUNT + 2, peer.GetChildren().Count, "GetChildren.Count #1"); // We add one TextBlock stackPanel.Children.Add(new TextBlock() { Text = "Text2" }); Assert.IsNotNull(peer.GetChildren(), "GetChildren #2"); Assert.AreEqual(INITIAL_CHILDREN_COUNT + 3, peer.GetChildren().Count, "GetChildren.Count #2"); }); EnqueueTestComplete(); }
public override void GetChildrenChanged() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } TestPanel.Children.Clear(); datagrid = CreateDataGrid(); ContentControl control = null; AutomationPeer peer = null; List <AutomationPeer> children = null; AutomationEventTuple tuple = null; object oldContent = null; CreateAsyncTest(datagrid, () => { peer = GetDataGridColumnHeader(datagrid); control = ((FrameworkElementAutomationPeer)peer).Owner as ContentControl; oldContent = control.Content; Assert.IsNotNull(peer, "Peer"); children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #0"); Assert.AreEqual(1, children.Count, "GetChildren #1"); }, () => { control.Content = "Hello"; }, () => { children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #1"); Assert.AreEqual(1, children.Count, "Children.Count #0"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged); Assert.IsNotNull(tuple, "StructureChanged #0"); EventsManager.Instance.Reset(); }, () => control.Content = null, () => { Assert.IsNotNull(peer.GetChildren(), "GetChildren #3"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged); Assert.IsNotNull(tuple, "StructureChanged #1"); EventsManager.Instance.Reset(); control.Content = oldContent; }, () => { children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #4"); Assert.AreEqual(1, children.Count, "Children.Count #1"); tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged); Assert.IsNotNull(tuple, "StructureChanged #6"); }); }
public override void ContentTest() { Assert.IsTrue(IsContentPropertyElement(), "ItemsControl ContentElement."); bool concreteLoaded = false; ItemsControlConcrete concrete = CreateConcreteFrameworkElement() as ItemsControlConcrete; concrete.Loaded += (o, e) => concreteLoaded = true; TestPanel.Children.Add(concrete); // StackPanel with two TextBlocks bool stackPanelLoaded = false; StackPanel stackPanel = new StackPanel(); stackPanel.Children.Add(new TextBlock() { Text = "Text0" }); stackPanel.Children.Add(new TextBlock() { Text = "Text1" }); stackPanel.Loaded += (o, e) => stackPanelLoaded = true; EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0"); Enqueue(() => concrete.ApplyTemplate()); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNull(peer.GetChildren(), "GetChildren #0"); concrete.Items.Add(stackPanel); // Also one extra TextBlock concrete.Items.Add(new TextBlock() { Text = "Text2" }); }); EnqueueConditional(() => concreteLoaded && stackPanelLoaded, "ConcreteLoaded #1"); Enqueue(() => { stackPanelLoaded = false; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNull(peer.GetChildren(), "GetChildren #1"); // We add another TextBlock and nothing changes stackPanel.Children.Add(new TextBlock() { Text = "Text3" }); Assert.IsNull(peer.GetChildren(), "GetChildren #2"); }); EnqueueTestComplete(); }
public override void ContentTest() { Button button = null; StackPanel stackPanel = null; object oldContent = null; CreateAsyncTest(calendar, () => { List <AutomationPeer> buttonChildren = GetButtonChildren(); // StackPanel and two TextBlocks stackPanel = new StackPanel(); stackPanel.Children.Add(new TextBlock() { Text = "Text0" }); stackPanel.Children.Add(new TextBlock() { Text = "Text1" }); button = ((FrameworkElementAutomationPeer)buttonChildren [0]).Owner as Button; oldContent = button.Content; }, () => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(button); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #0"); Assert.AreEqual(1, children.Count, "GetChildren.Count #0"); button.Content = stackPanel; }, () => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(button); Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); Assert.AreEqual(2, peer.GetChildren().Count, "GetChildren.Count #1"); // We add one TextBlock stackPanel.Children.Add(new TextBlock() { Text = "Text2" }); Assert.IsNotNull(peer.GetChildren(), "GetChildren #2"); Assert.AreEqual(3, peer.GetChildren().Count, "GetChildren.Count #2"); }, () => button.Content = oldContent, () => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(button); List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #3"); Assert.AreEqual(1, children.Count, "GetChildren.Count #3"); }); }
public override void ContentTest() { Assert.IsTrue(IsContentPropertyElement(), "ToggleButton ContentElement."); bool tbLoaded = false; ToggleButton toggleButton = CreateConcreteFrameworkElement() as ToggleButton; toggleButton.Loaded += (o, e) => tbLoaded = true; TestPanel.Children.Add(toggleButton); // StackPanel and two TextBlocks bool stackPanelLoaded = false; StackPanel stackPanel = new StackPanel(); stackPanel.Children.Add(new TextBlock() { Text = "Text0" }); stackPanel.Children.Add(new TextBlock() { Text = "Text1" }); stackPanel.Loaded += (o, e) => stackPanelLoaded = true; EnqueueConditional(() => tbLoaded, "ToggleButton Loaded #0"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement( toggleButton); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNull(peer.GetChildren(), "GetChildren #0"); toggleButton.Content = stackPanel; }); EnqueueConditional(() => tbLoaded && stackPanelLoaded, "ToggleButton Loaded #1"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement( toggleButton); Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); Assert.AreEqual(2, peer.GetChildren().Count, "GetChildren.Count #1"); // We add one TextBlock stackPanel.Children.Add(new TextBlock() { Text = "Text2" }); Assert.IsNotNull(peer.GetChildren(), "GetChildren #2"); Assert.AreEqual(3, peer.GetChildren().Count, "GetChildren.Count #2"); }); EnqueueTestComplete(); }
/// <summary> /// Recursively sets the value of AccessibilityView and Name for children of <paramref name="elementPeer"/> /// based on ImportantForAccessibility and AccesibilityLabel /// </summary> /// <param name="elementPeer"></param> /// <param name="hideNodes"></param> /// <param name="traverseAllChildren"></param> private static void SetChildrenAccessibilityViewAndNameForPeer(AutomationPeer elementPeer, bool hideNodes, bool traverseAllChildren) { if (elementPeer?.GetChildren() == null) { return; } foreach (AutomationPeer childPeer in elementPeer.GetChildren()) { UIElement child = GetUIElementFromAutomationPeer(childPeer); // Take into account just views created by React if (child == null || !child.HasTag()) { SetChildrenAccessibilityViewAndNameForPeer(childPeer, hideNodes, traverseAllChildren); } else { if (traverseAllChildren || GetDirty(child)) { UpdateAccessibilityViewAndNameForUIElement(child, childPeer, hideNodes); } SetDirty(child, false); } } }
public void ItemsSource() { ListBox listbox = new ListBox(); List <Car> carList = new List <Car> (); carList.Add(new Car() { Name = "Ferrari", Price = 150000 }); carList.Add(new Car() { Name = "Honda", Price = 12500 }); carList.Add(new Car() { Name = "Toyota", Price = 11500 }); listbox.DisplayMemberPath = "Name"; listbox.ItemsSource = carList; CreateAsyncTest(listbox, () => { AutomationPeer listboxPeer = FrameworkElementAutomationPeer.CreatePeerForElement(listbox); List <AutomationPeer> children = listboxPeer.GetChildren(); Assert.IsNotNull(children, "#0"); Assert.AreEqual(3, children.Count, "#1"); Assert.AreEqual("Ferrari 150000", children [0].GetName(), "#2"); Assert.AreEqual("Honda 12500", children [1].GetName(), "#3"); Assert.AreEqual("Toyota 11500", children [2].GetName(), "#4"); }); }
/// <inheritdoc /> protected override IList <AutomationPeer> GetChildrenCore() { var automationPeers = new List <AutomationPeer>(); if (this.AutoCompleteBox != null && this.AutoCompleteBox.IsTemplateApplied) { AutomationPeer tBoxPeer = CreatePeerForElement(this.AutoCompleteBox.textbox); automationPeers.Insert(0, tBoxPeer); AutomationPeer suggestionControlPeer = CreatePeerForElement(this.AutoCompleteBox.suggestionsControl); if (suggestionControlPeer != null) { IList <AutomationPeer> listChildren = suggestionControlPeer.GetChildren(); if (listChildren != null) { foreach (AutomationPeer child in listChildren) { automationPeers.Add(child); } } } } return(automationPeers); }
public override void GetName() { Assert.IsTrue(IsContentPropertyElement(), "SelectorItem ContentElement."); bool listboxLoaded = false; ListBox listbox = new ListBox(); ListBoxItem concrete = CreateConcreteFrameworkElement() as ListBoxItem; listbox.Loaded += (o, e) => listboxLoaded = true; listbox.Items.Add(concrete); TestPanel.Children.Add(listbox); EnqueueConditional(() => listboxLoaded, "ListBoxLoaded #0"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(listbox); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "GetChildren #0"); Assert.AreEqual(1, children.Count, "GetChildren.Count #0"); Assert.AreEqual(string.Empty, children[0].GetName(), "children[0].GetName #0"); concrete.Content = "ListBoxItem0"; Assert.AreEqual("ListBoxItem0", children[0].GetName(), "children[0].GetName #1"); concrete.Content = "Hellooooooooo"; Assert.AreEqual("Hellooooooooo", children[0].GetName(), "children[0].GetName #2"); Assert.IsNull(children [0].GetChildren(), "children[0].GetChildren"); }); EnqueueTestComplete(); }
public override void ContentTest() { Assert.IsTrue(IsContentPropertyElement(), "SelectorItem ContentElement."); bool concreteLoaded = false; ListBoxItem concrete = CreateConcreteFrameworkElement() as ListBoxItem; concrete.Loaded += (o, e) => concreteLoaded = true; TestPanel.Children.Add(concrete); // StackPanel with two TextBlocks bool stackPanelLoaded = false; StackPanel stackPanel = new StackPanel(); stackPanel.Children.Add(new TextBlock() { Text = "Text0" }); stackPanel.Children.Add(new TextBlock() { Text = "Text1" }); stackPanel.Loaded += (o, e) => stackPanelLoaded = true; EnqueueConditional(() => concreteLoaded, "SelectorItemConcreteLoaded #0"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNull(peer.GetChildren(), "GetChildren #0"); concrete.Content = stackPanel; }); EnqueueConditional(() => concreteLoaded && stackPanelLoaded, "SelectorItemConcreteLoaded #1"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); // Is 2 because StackPanel is wrapped into 1 ListBoxItem Assert.AreEqual(2, peer.GetChildren().Count, "GetChildren.Count #1"); // We add another TextBlock stackPanel.Children.Add(new TextBlock() { Text = "Text3" }); Assert.AreEqual(3, peer.GetChildren().Count, "GetChildren.Count #2"); }); EnqueueTestComplete(); }
public void ISelectionProvider_Methods() { TabControl tabControl = new TabControl(); ISelectionProvider selectionProvider = null; AutomationPeer peer = null; CreateAsyncTest(tabControl, () => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); Assert.IsNotNull(peer, "#0"); selectionProvider = (ISelectionProvider)peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider); Assert.IsNull(peer.GetChildren(), "#1"); }, () => { Assert.IsFalse(selectionProvider.CanSelectMultiple, "#2"); Assert.IsTrue(selectionProvider.IsSelectionRequired, "#3"); Assert.IsNull(selectionProvider.GetSelection(), "#4"); tabControl.Items.Add(new TabItem() { Header = "Item0" }); tabControl.Items.Add(new TabItem() { Header = "Item1" }); }, () => { List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "#5"); Assert.AreEqual(2, children.Count, "#6"); IRawElementProviderSimple[] selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "#7"); Assert.AreEqual(1, selection.Length, "#8"); Assert.AreEqual("Item0", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "#9"); }, () => tabControl.SelectedIndex = 1, () => { IRawElementProviderSimple[] selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "#10"); Assert.AreEqual(1, selection.Length, "#11"); Assert.AreEqual("Item1", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "#12"); }); }
private List <AutomationPeer> GetButtonChildren() { AutomationPeer calendarPeer = FrameworkElementAutomationPeer.CreatePeerForElement(calendar); return((from peer in calendarPeer.GetChildren() where peer.GetType() == typeof(CalendarButtonAutomationPeer) select peer).ToList <AutomationPeer> ()); }
protected virtual void ContentTest_Template(Selector concrete) { // We are going to add a lot of elements to show the scrollbars // notice we are using default Template bool concreteLoaded = false; bool concreteLayoutUpdate = false; concrete.Width = 250; concrete.Height = 300; concrete.Loaded += (o, e) => concreteLoaded = true; concrete.LayoutUpdated += (o, e) => concreteLayoutUpdate = true; TestPanel.Children.Add(concrete); // StackPanel with two TextBlocks EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNull(peer.GetChildren(), "GetChildren #0"); concreteLayoutUpdate = false; for (int index = 0; index < 100; index++) { concrete.Items.Add(string.Format("Item {0}", index)); } }); EnqueueConditional(() => concreteLoaded && concreteLayoutUpdate, "ConcreteLoaded #1"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); Assert.AreEqual(concrete.Template == null, peer.GetPattern(PatternInterface.Scroll) == null, "ScrollPattern #0"); Assert.AreEqual(100, peer.GetChildren().Count, "GetChildren.Count #1"); concreteLayoutUpdate = false; concrete.Items.Add("I'm looooooooooooooooooooooooooooooooooooooooooooong!"); }); EnqueueConditional(() => concreteLoaded && concreteLayoutUpdate, "ConcreteLoaded #1"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); Assert.AreEqual(101, peer.GetChildren().Count, "GetChildren.Count #2"); }); EnqueueTestComplete(); }
protected override void ContentTest_Template(Selector selectorConcrete) { Assert.IsTrue(IsContentPropertyElement(), "ComboBox ContentElement."); bool concreteLoaded = false; bool expanded = false; ComboBoxConcrete concrete = (ComboBoxConcrete)selectorConcrete; concrete.Width = 300; concrete.Loaded += (o, e) => concreteLoaded = true; concrete.DropDownOpened += (o, e) => expanded = true; TestPanel.Children.Add(concrete); concrete.Items.Add("Item 0"); concrete.Items.Add("Item 1"); EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0"); Enqueue(() => concrete.ApplyTemplate()); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.AreEqual(concrete.Template == null, peer.GetChildren() != null, "GetChildren #0"); }); Enqueue(() => concrete.IsDropDownOpen = true); EnqueueConditional(() => expanded, "Expanded #0"); Enqueue(() => concrete.IsDropDownOpen = false); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); Assert.AreEqual(2, peer.GetChildren().Count, "GetChildren.Count #1"); }); Enqueue(() => concrete.Items.Add(new TextBlock() { Text = "Item 2" })); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete); Assert.IsNotNull(peer.GetChildren(), "GetChildren #2"); Assert.AreEqual(3, peer.GetChildren().Count, "GetChildren.Count #2"); }); EnqueueTestComplete(); }
protected override List <AutomationPeer> GetChildrenCore() { AutomationPeer wrapperPeer = this.GetWrapperPeer(); if (wrapperPeer != null) { return(wrapperPeer.GetChildren()); } return(null); }
/// <summary> /// Generates name for <paramref name="peer"/>. /// Takes into account <see cref="AccessibilityLabelAttachedProperty"/>. /// Does not take into account <see cref="ImportantForAccessibilityAttachedProperty"/> /// on <paramref name="peer"/> itself but does take it into account on children transitively. /// This assumes that the caller knows that the <see cref="AccessibilityLabelAttachedProperty"/> on /// <paramref name="peer"/> must be taken into account no matter what is the value of /// <see cref="ImportantForAccessibilityAttachedProperty"/> on it. /// </summary> /// <param name="peer">Peer to generate name for.</param> /// <returns>The generated name.</returns> private static string GenerateNameFromUpdated(AutomationPeer peer) { var element = GetUIElementFromAutomationPeer(peer); var label = GetAccessibilityLabelAttached(element); if (!string.IsNullOrEmpty(label)) { return(label); } return(GenerateNameFromChildren(peer.GetChildren())); }
public static AutomationPeer Navigate(this AutomationPeer peer, NavigateDirection direction) { List <AutomationPeer> children = null; if (direction == NavigateDirection.FirstChild || direction == NavigateDirection.LastChild) { children = peer.GetChildren(); if (children == null || children.Count == 0) { return(null); } if (direction == NavigateDirection.FirstChild) { return(children [0]); } return(children [children.Count - 1]); } var parent = peer.GetParent(); if (direction == NavigateDirection.Parent || parent == null) { return(parent); } children = parent.GetChildren(); if (children == null) { return(null); } AutomationPeer previous = null; AutomationPeer current = null; foreach (AutomationPeer child in children) { previous = current; current = child; if (child == peer && direction == NavigateDirection.PreviousSibling) { return(previous); } if (previous == peer && direction == NavigateDirection.NextSibling) { return(current); } } return(null); }
public void AllTests() { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(CreateConcreteFrameworkElement()); // ContentTest Assert.IsNull(peer.GetChildren(), "#0"); // IsContentElement Assert.IsFalse(peer.IsContentElement(), "IsContentElement"); // GetClassName Assert.AreEqual("DataGridDetailsPresenter", peer.GetClassName(), "GetClassNameCore"); }
private AutomationPeer GetDataGridColumnHeader(DataGrid datagrid) { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(datagrid); List <AutomationPeer> children = peer.GetChildren(); foreach (AutomationPeer child in children) { if (child.GetAutomationControlType() == AutomationControlType.Header) { return(child.GetChildren() [0]); } } return(null); }
public override void ContentTest() { Popup popup = new Popup(); AutomationPeer peer = null; StackPanel stackPanel = null; CreateAsyncTest(popup, () => { // StackPanel and two TextBlocks stackPanel = new StackPanel(); stackPanel.Children.Add(new TextBlock() { Text = "Text0" }); stackPanel.Children.Add(new TextBlock() { Text = "Text1" }); }, () => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(popup); Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement"); Assert.IsNull(peer.GetChildren(), "GetChildren #0"); popup.Child = stackPanel; }, () => { Assert.IsNotNull(peer.GetChildren(), "GetChildren #1"); Assert.AreEqual(2, peer.GetChildren().Count, "GetChildren.Count #1"); // We add one TextBlock stackPanel.Children.Add(new TextBlock() { Text = "Text2" }); Assert.IsNotNull(peer.GetChildren(), "GetChildren #2"); Assert.AreEqual(3, peer.GetChildren().Count, "GetChildren.Count #2"); }); }
/// protected override List <AutomationPeer> GetChildrenCore() { AutomationPeer wrapperPeer = OwningRowPeer; if (wrapperPeer != null) { // We need to update children manually since wrapperPeer is not in the Automation Tree // When containers are recycled the visual (DataGridRow) will point to a new item. // WrapperPeer's children are the peers for DataGridRowHeader, DataGridCells and DataGridRowDetails. wrapperPeer.ResetChildrenCache(); return(wrapperPeer.GetChildren()); } return(GetCellItemPeers()); }
public void AllTests() { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(CreateConcreteFrameworkElement()); // GetClassName Assert.AreEqual("DataGridRowsPresenter", peer.GetClassName(), "GetClassNameCore"); // IsContent Assert.IsFalse(peer.IsContentElement(), "IsContentElement"); // GetChildren and Content List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "#0"); Assert.AreEqual(0, children.Count, "#1"); }
public void AllTests() { DataGridColumnHeader fe = CreateConcreteFrameworkElement() as DataGridColumnHeader; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(fe); // GetAutomationControlType Assert.AreEqual(AutomationControlType.HeaderItem, peer.GetAutomationControlType(), "GetAutomationControlType"); // GetBoundingRectangle Rect boundingRectangle = peer.GetBoundingRectangle(); Assert.AreNotEqual(0, boundingRectangle.X, "GetBoundingRectangle X"); Assert.AreNotEqual(0, boundingRectangle.Y, "GetBoundingRectangle Y"); Assert.AreNotEqual(0, boundingRectangle.Width, "GetBoundingRectangle Width"); Assert.AreNotEqual(0, boundingRectangle.Height, "GetBoundingRectangle Height"); // GetChildren List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "#0"); Assert.AreEqual(1, children.Count, "#1"); // IsKeyboardFocusable Assert.IsFalse(peer.IsKeyboardFocusable(), "IsKeyboardFocusable"); // GetClassName Assert.AreEqual("DataGridColumnHeader", peer.GetClassName(), "#0"); // IsContentElement Assert.IsFalse(peer.IsContentElement(), "#0"); // GetName Assert.AreEqual(fe.Content, peer.GetName(), "GetName"); // GetClickablePoint Point p = peer.GetClickablePoint(); Assert.IsFalse(double.IsNaN(p.X), "#0"); Assert.IsFalse(double.IsNaN(p.Y), "#1"); // GetParent Assert.IsNotNull(peer.GetParent(), "GetParent"); // IsOffscreen Assert.IsFalse(peer.IsOffscreen(), "IsOffScreen"); }
/// <summary> /// Recursively sets AccessibilityView to <paramref name="accessibilityView"/> for <paramref name="parentPeer"/> children. /// </summary> /// <param name="parentPeer"></param> /// <param name="accessibilityView"></param> private static void SetChildrenAccessibilityView(AutomationPeer parentPeer, AccessibilityView accessibilityView) { if (parentPeer?.GetChildren() == null) { return; } foreach (AutomationPeer childPeer in parentPeer.GetChildren()) { UIElement child = GetUIElementFromAutomationPeer(childPeer); if (child != null) { AutomationProperties.SetAccessibilityView(child, accessibilityView); } SetChildrenAccessibilityView(childPeer, accessibilityView); } }
/// <summary> /// Recursively sets the value of AccessibilityView according ImportantForAccessibility setting /// for children of <paramref name="elementPeer"/> /// </summary> /// <param name="elementPeer"></param> private static void SetChildrenAccessibilityViewFromImportantForAccessibility(AutomationPeer elementPeer) { if (elementPeer?.GetChildren() == null) { return; } foreach (AutomationPeer childPeer in elementPeer.GetChildren()) { UIElement child = GetUIElementFromAutomationPeer(childPeer); if (child == null) { SetChildrenAccessibilityViewFromImportantForAccessibility(childPeer); } else { var importantForAccessibilityAttached = GetImportantForAccessibilityAttached(child); UpdateAccessibilityViewForUIElement(child, childPeer, importantForAccessibilityAttached); } } }
/// <summary> /// Generates name from peer and list of children. /// Warning! It has clearing the Name AP as a side effect! /// </summary> /// <param name="peer"></param> /// <returns>Generated name.</returns> private static string GenerateNameFromPeer(AutomationPeer peer) { // Clear Name attached property to unhide any name generated by peer var element = GetUIElementFromAutomationPeer(peer); if (element != null) { element.ClearValue(AutomationProperties.NameProperty); } var ownName = peer.GetName(); if (!string.IsNullOrEmpty(ownName)) { // Own name present, we can use return(ownName); } // Defer to children return(GenerateNameFromChildren(peer.GetChildren())); }
public void IGridItemProvider_Methods() { AutomationPeer calendarAutomationPeer = null; DateTime date = new DateTime(2000, 2, 2); List <AutomationPeer> buttonChildren = null; CreateAsyncTest(calendar, () => { calendarAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(calendar); Assert.IsNotNull(calendarAutomationPeer, "#0"); buttonChildren = GetButtonChildren(); Assert.IsNotNull(buttonChildren.Count, "#1"); Assert.AreEqual(12, buttonChildren.Count, "#2"); }, () => { calendar.SelectedDate = date; }, () => { int count = 0; foreach (AutomationPeer peer in (from c in calendarAutomationPeer.GetChildren() where c.GetType() == typeof(CalendarButtonAutomationPeer) select c)) { FrameworkElementAutomationPeer feap = peer as FrameworkElementAutomationPeer; Assert.IsNotNull("#3"); IGridItemProvider gridItem = (IGridItemProvider)peer.GetPattern(PatternInterface.GridItem); Assert.IsNotNull(gridItem, "#4"); Assert.AreEqual(feap.Owner.GetValue(Grid.ColumnProperty), gridItem.Column, "#5"); Assert.AreEqual((int)feap.Owner.GetValue(Grid.RowProperty), gridItem.Row, "#6"); Assert.AreEqual(1, gridItem.ColumnSpan, "#7"); Assert.AreEqual(1, gridItem.RowSpan, "#8"); Assert.AreEqual(calendarAutomationPeer, new PeerFromProvider().GetPeerFromProvider(gridItem.ContainingGrid), "#9"); count++; } Assert.AreEqual(12, count, "#10"); }); }
/// <summary> /// Recursively sets AccessibilityView to <paramref name="accessibilityView"/> for <paramref name="parentPeer"/> children. /// </summary> /// <param name="parentPeer"></param> /// <param name="accessibilityView"></param> private static void SetChildrenAccessibilityView(AutomationPeer parentPeer, AccessibilityView accessibilityView) { if (parentPeer?.GetChildren() == null) { return; } foreach (AutomationPeer childPeer in parentPeer.GetChildren()) { UIElement child = GetUIElementFromAutomationPeer(childPeer); if (child != null) { AutomationProperties.SetAccessibilityView(child, accessibilityView); // If element is hidden clear the generated label if any. if (IsInGenerativeStateAndHidden(child)) { child.ClearValue(AutomationProperties.NameProperty); } } SetChildrenAccessibilityView(childPeer, accessibilityView); } }