如何防止根据条件选择 TreeViewItem
我有 wpf TreeView——绑定到一些数据。 树视图位于窗口的左侧,该窗口分为两个区域,其中树是导航,右侧的面板根据所选的树节点更改内容。
并非树视图的所有节点都会生成详细信息。 我想禁用这些节点的选择。有什么想法吗?
谢谢
I have wpf TreeView -- bound to some data.
The Treeview resides on the left hand of a window divided into two areas where the tree is the navigation and a panel on the right side changes content depending on the tree node selected.
Not all the nodes of the treeview produce detail information.
I want to disable the selection of those nodes. Any idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@jama64:如果将样式从 Property IsEnabled 更改为 Focusable,您就可以实现您想要的效果。
@jama64 : You can achieve what you want if you change the Style from Property IsEnabled to Focusable.
您的源代码中是否有类似布尔属性的内容,称为
HasDetails
或其他内容?在这种情况下,你可以使用这样的东西。在 ItemContainerStyle 中创建一个 MultiDataTrigger,该触发器绑定到 DataContext 中的HasDetails
和TreeViewItem
的IsSelected
,并且如果两者都为 True(好吧,HasDetails 为 True)为 False:-),您启动一个 Storyboard,“取消选择”新选择的TreeViewItem
。这将禁用所有没有详细信息的
TreeViewItem
的选择,但它们仍然可以展开。希望这就是您正在寻找的更新
要禁用HasDetails为False的
TreeViewItem
,您可以使用此Do you have something like a boolean property in your source called
HasDetails
or something? In that case you can use something like this. Create a MultiDataTrigger in the ItemContainerStyle that binds toHasDetails
in the DataContext andIsSelected
for theTreeViewItem
and if both are True (well, True that HasDetails is False:-), you start a Storyboard that "unselects" the newly selectedTreeViewItem
.This will disable selection for all the
TreeViewItem
's that doesn't have details but they will still be expandable. Hopefully that was what you were looking forUpdate
To disable the
TreeViewItem
's where HasDetails is False you can use this