Treeview 是否使用命令绑定来展开/折叠?
WPF Treeview 响应 + 和 - 击键来展开和折叠树中的节点。伟大的!
是否有一个现有命令可以绑定工具栏按钮或菜单项以在树视图中执行相同的操作?我在库存命令常量中没有看到任何与展开/折叠相关的内容。
The WPF Treeview responds to + and - keystrokes to expand and collapse nodes in the tree. Great!
Is there an existing command I can bind my toolbar buttons or menu items to to perform the same actions in the treeview? I don't see anything related to expand/collapse in the stock command constants.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TreeView
通过将ToggleButton.IsChecked
绑定到TreeViewItem.IsExpanded
中的鼠标来处理TreeViewItem
的展开。ControlTemplate
并在覆盖TreeViewItem.OnKeyDown
中处理键盘扩展。所以,不,它在实现中不使用命令。但您可以毫不费力地添加自己的命令。在此示例中,我向
TreeView
添加了一个行为,以便它响应标准的Open
和Close
应用程序命令:以下是使其起作用的行为:
如果您不熟悉行为,请首先添加此命名空间:
并将相应的引用添加到您的项目中。
The
TreeView
handles the expansion of aTreeViewItem
with the mouse by bindingToggleButton.IsChecked
toTreeViewItem.IsExpanded
in theControlTemplate
and handles expansion with the keyboard in an overrideTreeViewItem.OnKeyDown
. So, no, it doesn't use commands in its implementation.But you can add your own commands without much effort. In this example, I've added a behavior to a
TreeView
so that it responds to the standardOpen
andClose
application commands:and here is the behavior that makes that work:
If you are not familiar with behaviors, first add this namespace:
and add the corresponding reference to your project.