public virtual void TreeViewPeerSupportsScrolling() { // Note: This test fails if ItemsSource isn't set because it // requires a container to find the ItemsHost and ScrollHost. TreeView view = new TreeView { ItemsSource = new int[] { 1, 2, 3 } }; TreeViewAutomationPeer peer = null; IScrollProvider provider = null; TestAsync( view, () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer, () => provider = peer.GetPattern(PatternInterface.Scroll) as IScrollProvider, () => Assert.IsNotNull(provider, "IScrollProvider peer should not be null!"), () => { FrameworkElementAutomationPeer scroll = provider as FrameworkElementAutomationPeer; Assert.IsNotNull(scroll, "IScrollProvider should be an automation peer!"); Assert.IsInstanceOfType(scroll.Owner, typeof(ScrollViewer), "IScrollProvider should wrap a ScrollViewer!"); for (UIElement current = scroll.Owner; current != null; current = VisualTreeHelper.GetParent(current) as UIElement) { if (current == view) { return; } } Assert.Fail("IScrollProvider should be an automation peer for a child of the TreeView!"); }); }
public static ScrollViewer GetScrollViewer(this TreeView treeView1) { TreeViewAutomationPeer vap = new TreeViewAutomationPeer(treeView1); var svap = vap.GetPattern(PatternInterface.Scroll) as ScrollViewerAutomationPeer; var scroller = svap.Owner as ScrollViewer; return(scroller); }
public virtual void TreeViewPeerGetNoItems() { TreeView view = new TreeView(); TreeViewAutomationPeer peer = null; TestAsync( view, () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer, () => Assert.IsNull(peer.GetChildren(), "There should be no children when the TreeView does not have items!")); }
/// <summary> /// Notify the tree update when search is complete. /// </summary> private void FireAsyncContentLoadedEvent() { if (AutomationPeer.ListenerExists(AutomationEvents.AsyncContentLoaded)) { TreeViewAutomationPeer peer = UIElementAutomationPeer.FromElement(this.treeviewHierarchy) as TreeViewAutomationPeer; if (peer != null) { peer.RaiseAsyncContentLoadedEvent(new AsyncContentLoadedEventArgs(AsyncContentLoadedState.Completed, 100)); } } }
public static ScrollViewer GetTreeViewScrollViewer(TreeView treeView) { //对于TreeView而言: TreeViewAutomationPeer lvap = new TreeViewAutomationPeer(treeView); var svap = lvap.GetPattern(PatternInterface.Scroll) as ScrollViewerAutomationPeer; var scroll = svap?.Owner as ScrollViewer; return(scroll); //////////////////////////此处添加你想要对TreeView自身滚动条的操作/////////////////////////// // scroll.ScrollToVerticalOffset(scroll.VerticalOffset+1); //向下调节垂直滚动条的位置; }
public virtual void TreeViewAutomationPeerTypeAndClass() { TreeView view = new TreeView(); TreeViewAutomationPeer peer = null; TestAsync( view, () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer, () => Assert.AreEqual(AutomationControlType.Tree, peer.GetAutomationControlType(), "Unexpected AutomationControlType!"), () => Assert.AreEqual("TreeView", peer.GetClassName(), "Unexpected ClassType!")); }
public virtual void TreeViewCreatesAutomationPeer() { TreeView view = new TreeView(); TreeViewAutomationPeer peer = null; TestAsync( view, () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer, () => Assert.IsNotNull(peer, "TreeView peer should not be null!"), () => Assert.AreEqual(view, peer.Owner, "TreeView should be owner of the peer!")); }
public virtual void TreeViewPeerSupportsSelection() { TreeView view = new TreeView(); TreeViewAutomationPeer peer = null; ISelectionProvider provider = null; TestAsync( view, () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer, () => provider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider, () => Assert.IsNotNull(provider, "ISelectionProvider peer should not be null!")); }
public virtual void TreeViewPeerGetWithItems() { TreeView view = new TreeView { ItemsSource = new int[] { 1, 2, 3 } }; TreeViewAutomationPeer peer = null; List <AutomationPeer> items = null; TestAsync( view, () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer, () => items = peer.GetChildren(), () => Assert.AreEqual(3, items.Count, "Unexpected number of child peers!"), () => Assert.IsInstanceOfType(items[0], typeof(TreeViewItemAutomationPeer), "Child peer is not a TreeViewItemAutomationPeer!")); }
public virtual void TreeViewPeerOnlySupportsScrollingAndSelection() { TreeView view = new TreeView(); TreeViewAutomationPeer peer = null; TestAsync( view, () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer, () => Assert.IsNull(peer.GetPattern(PatternInterface.Dock), "TreeViewAutomationPeer should not support the Dock pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.ExpandCollapse), "TreeViewAutomationPeer should not support the ExpandCollapse pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.Grid), "TreeViewAutomationPeer should not support the Grid pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.GridItem), "TreeViewAutomationPeer should not support the GridItem pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.Invoke), "TreeViewAutomationPeer should not support the Dock pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.MultipleView), "TreeViewAutomationPeer should not support the MultipleView pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.RangeValue), "TreeViewAutomationPeer should not support the RangeValue pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.ScrollItem), "TreeViewAutomationPeer should not support the ScrollItem pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.SelectionItem), "TreeViewAutomationPeer should not support the SelectionItem pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.Table), "TreeViewAutomationPeer should not support the Table pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.TableItem), "TreeViewAutomationPeer should not support the TableItem pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.Toggle), "TreeViewAutomationPeer should not support the Toggle pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.Transform), "TreeViewAutomationPeer should not support the Transform pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.Value), "TreeViewAutomationPeer should not support the Value pattern!"), () => Assert.IsNull(peer.GetPattern(PatternInterface.Window), "TreeViewAutomationPeer should not support the Window pattern!")); }