【问题标题】:How to set focus to a control in a TreeViewItem when selected选择时如何将焦点设置到 TreeViewItem 中的控件
【发布时间】:2010-12-09 09:54:54
【问题描述】:

我有一个TreeView,其中的项目由HierarchicalDataTemplates 定义。创建的每个TreeViewItem 都包含一些TextBoxes。 When a TreeViewItem is selected I want to set the Keyboard Focus to a TextBox of the TreeViewItem (the TextBoxhas the name TextBox1).我该怎么做?

【问题讨论】:

    标签: wpf treeview focus treeviewitem


    【解决方案1】:

    有很多方法可以做到这一点。这只是其中之一。使用我的FocusExtension. IsFocused 附加属性。如果下面没有 ViewModel,请将其绑定到 TreeViewItem.IsSelectedProperty。像

    <TextBox local:FocusExtension.IsFocused="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
    

    应该可以。我从头输入,没有检查语法。复制粘贴时要小心:)。

    【讨论】:

    • 非常感谢。我会试试这个。
    猜你喜欢
    • 2011-06-08
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多