Data binding 如何向数据绑定树视图中的项添加命令
如何将WPF添加到绑定到中的项目?我使用的是MVVM模式和复合WPF,我希望在用户双击Data binding 如何向数据绑定树视图中的项添加命令,data-binding,mvvm,treeview,command,cag,Data Binding,Mvvm,Treeview,Command,Cag,如何将WPF添加到绑定到中的项目?我使用的是MVVM模式和复合WPF,我希望在用户双击TreeView中的某个项目时调用该命令 我在XAML中定义了一个TreeView,其DataContext设置为XmlDataProvider: <TreeView xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2
TreeView
中的某个项目时调用该命令
我在XAML中定义了一个
TreeView
,其DataContext
设置为XmlDataProvider
:
<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 XPath=@SomeAttribute}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
如何使用上面的
TreeView
?您应该使用附加的命令行为模式。回答了一个类似的问题,但在ListView中。我还发现了关于StackOverflow()的另一个问题,以及一个使用TreeView()的常规附加行为的示例@emddudley:是的,您的第一个链接是我在一个项目中用于向列表框添加双clic命令的链接,它工作得非常好
<MenuItem Command="{Binding NewCommand}" Header="_New" />