当前位置: 首页>>代码示例>>C#>>正文


C# TreeViewItem.GetVisualChild方法代码示例

本文整理汇总了C#中System.Windows.Controls.TreeViewItem.GetVisualChild方法的典型用法代码示例。如果您正苦于以下问题:C# TreeViewItem.GetVisualChild方法的具体用法?C# TreeViewItem.GetVisualChild怎么用?C# TreeViewItem.GetVisualChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.TreeViewItem的用法示例。


在下文中一共展示了TreeViewItem.GetVisualChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExpanderButtonFocusActivatesSelection

        public virtual void ExpanderButtonFocusActivatesSelection()
        {
            StackPanel root = new StackPanel();
            TreeView view = new TreeView();
            TreeViewItem item = new TreeViewItem { Header = "Item" };
            Button button = new Button { Content = "Button" };
            view.Items.Add(item);
            root.Children.Add(view);
            root.Children.Add(button);
            ToggleButton ExpanderButton = null;

            TestAsync(
                5,
                root,
                () => item.Focus(),
                () => Assert.IsTrue(item.IsSelected, "Item should be selected!"),
                () => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing!"),
                () => button.Focus(),
                () => Assert.IsFalse(item.IsSelectionActive, "Selection should be inactive after focusing on something else!"),
                () => ExpanderButton = item.GetVisualChild("ExpanderButton") as ToggleButton,
                () => Assert.IsNotNull(ExpanderButton, "Failed to find template part ExpanderButton!"),
                () => ExpanderButton.Focus(),
                () => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing ExpanderButton!"));
        }
开发者ID:royosherove,项目名称:cthru,代码行数:24,代码来源:TreeViewItemTest.cs

示例2: ExpanderButtonClickTogglesIsExpanded

        public virtual void ExpanderButtonClickTogglesIsExpanded()
        {
            TreeView view = new TreeView();
            TreeViewItem item = new TreeViewItem { Header = "Item", IsExpanded = true };
            TreeViewItem child = new TreeViewItem { Header = "Child" };
            view.Items.Add(item);
            item.Items.Add(child);
            ToggleButton ExpanderButton = null;
            AutomationPeer peer = null;
            IToggleProvider provider = null;

            TestAsync(
                5,
                view,
                () => ExpanderButton = item.GetVisualChild("ExpanderButton") as ToggleButton,
                () => Assert.IsNotNull(ExpanderButton, "Failed to find template part ExpanderButton!"),
                () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(ExpanderButton),
                () => provider = peer.GetPattern(PatternInterface.Toggle) as IToggleProvider,
                () => Assert.IsNotNull(provider, "IToggleProvider should not be null!"),
                () => provider.Toggle(),
                () => Assert.IsFalse(item.IsExpanded, "Item should be collapsed when clicking ExpanderButton!"),
                () => provider.Toggle(),
                () => Assert.IsTrue(item.IsExpanded, "Item should be expanded when clicking ExpanderButton again!"));
        }
开发者ID:royosherove,项目名称:cthru,代码行数:24,代码来源:TreeViewItemTest.cs


注:本文中的System.Windows.Controls.TreeViewItem.GetVisualChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。