本文整理汇总了C#中TreeViewItem.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# TreeViewItem.Focus方法的具体用法?C# TreeViewItem.Focus怎么用?C# TreeViewItem.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeViewItem
的用法示例。
在下文中一共展示了TreeViewItem.Focus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FocusSelects
public virtual void FocusSelects()
{
TreeView view = new TreeView();
TreeViewItem first = new TreeViewItem { Header = "First" };
TreeViewItem second = new TreeViewItem { Header = "Second" };
view.Items.Add(first);
view.Items.Add(second);
TestAsync(
view,
() => first.Focus(),
() => Assert.IsTrue(first.IsSelected, "First should be selected!"),
() => second.Focus(),
() => Assert.IsTrue(second.IsSelected, "Second should be selected!"),
() => Assert.IsFalse(first.IsSelected, "First should not be selected now!"));
}
示例2: SelectionInactiveOnLostFocus
public virtual void SelectionInactiveOnLostFocus()
{
StackPanel root = new StackPanel();
TreeView view = new TreeView();
TreeViewItem item = new TreeViewItem { Header = "Item" };
view.Items.Add(item);
Button other = new Button { Content = "Button" };
root.Children.Add(view);
root.Children.Add(other);
TestAsync(
root,
() => Assert.IsFalse(item.IsSelected, "Item should not be selected initially!"),
() => Assert.IsFalse(item.IsSelectionActive, "Item should not have inactive selection initially!"),
() => item.Focus(),
() => Assert.IsTrue(item.IsSelected, "Item should be selected after focus!"),
() => Assert.IsTrue(item.IsSelectionActive, "Item should not have inactive selection after focus!"),
() => other.Focus(),
() => Assert.IsTrue(item.IsSelected, "Item should be selected after focusing another element!"),
() => Assert.IsFalse(item.IsSelectionActive, "Item should have an inactive selection after focusing another element!"));
}
示例3: 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!"));
}