使TreeViewItem控件双击时执行命令
我正在 WPF 中寻找一种将命令绑定到 TreeViewItem 的方法,因此当我双击 TreeViewItem 时,会在我的 ViewModel(MVVM 模式)中执行 ICommand。 很像 Visual Studio 解决方案资源管理器。
我希望我可以使用类似 AttachedCommandBehaviour 的东西但这不起作用。我猜这是因为 TreeViewItem 本身不支持命令。
这是我的测试实现,它不起作用:
<TreeViewItem Header="Opret produktions ordre">
<acb:CommandBehaviorCollection.Behaviors>
<acb:BehaviorBinding Event="MouseLeftButtonDown" Command="{Binding TestCommand}"/>
</acb:CommandBehaviorCollection.Behaviors>
</TreeViewItem>
有人对如何使其工作有建议吗?或者您知道有一个控件可以为我提供此功能吗? 我当然希望有一个 MVVM 友好的解决方案。最好全部在 XAML 中。
I'm looking for a way, in WPF, to bind commands to a TreeViewItem, so when I double click a TreeViewItem a ICommand is executed in my ViewModel (MVVM pattern).
Much like the Visual Studio Solution Explorer.
I was hoping that I could use something like AttachedCommandBehaviour but that does not work. I guess it's because that the TreeViewItem itself does not support Commands.
Here is my test implementation which doesn't work:
<TreeViewItem Header="Opret produktions ordre">
<acb:CommandBehaviorCollection.Behaviors>
<acb:BehaviorBinding Event="MouseLeftButtonDown" Command="{Binding TestCommand}"/>
</acb:CommandBehaviorCollection.Behaviors>
</TreeViewItem>
Does anyone have a suggestion on how to make this work? Or maybe you know of a control that give me this functionality?
I am of course hoping for a MVVM friendly solution. Preferably all in XAML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过从 CodePlex 触发
InvokeDataCommand
触发器Expression Blend 示例库?如果您使用的是 WPF4,您将需要固定版本,请在此处阅读有关问题的信息:http://blog.thekieners.com/2010/11/09/expression-blend-samples-not-working-with-silverlight- 4-and-wpf-4/
从此处下载示例解决方案(这是更新版本):http://expressionblend.codeplex.com/workitem/8148
Have you tried
InvokeDataCommand
trigger from the CodePlex Expression Blend sample library?You will need the fixed version though if you're using WPF4, read about the issue here: http://blog.thekieners.com/2010/11/09/expression-blend-samples-not-working-with-silverlight-4-and-wpf-4/
Download the sample solution from here (this is the updated version): http://expressionblend.codeplex.com/workitem/8148