我正在寻找一种在 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 中。