1
如何将WPF DelegateCommand
s添加到绑定到XmlDataProvider
的TreeView
中的项目?我正在使用MVVM模式和Composite WPF,并且我想要在用户双击TreeView
中的某个项目时调用该命令。如何将命令添加到数据绑定中的项目TreeView
我在XAML其DataContext
被设置为XmlDataProvider
限定的TreeView
:
<TreeView
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ItemsSource="{Binding XPath=/SomeTopElement/*}">
<TreeView.Resources>
<HierarchicalDataTemplate
DataType="SomeElement"
ItemsSource="{Binding XPath=child::*}">
<TextBlock Text="{Binding [email protected]}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
在代码我简单地结合到DelegateCommand
在视图模型的其他部分:
<MenuItem Command="{Binding NewCommand}" Header="_New" />
这怎么能用上面的TreeView
完成?
我还发现StackOverflow另一个问题(http://stackoverflow.com/questions/926451/how-can-i-attach-two-attached-behaviors-to-one-xaml-element)和一个例子使用TreeView附加行为(http://www.codeproject.com/KB/WPF/AttachedBehaviors.aspx) – 2009-07-22 13:00:31