代码之家  ›  专栏  ›  技术社区  ›  sourcenouveau

如何向数据绑定树视图中的项添加命令

  •  1
  • sourcenouveau  · 技术社区  · 15 年前

    如何添加wpf DelegateCommand s到a中的项 TreeView 绑定到 XmlDataProvider ?我使用的是MVVM模式和复合WPF,我希望当用户双击 树视图 .


    我有一个 树视图 在XAML中定义,其 DataContext 设置为 XMLDATA提供程序 :

    <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>
    

    在代码的其他部分,我只是绑定到 委托代理 在视图模型中:

    <MenuItem Command="{Binding NewCommand}" Header="_New" />
    

    上面怎么办 树视图 ?

    1 回复  |  直到 15 年前
        1
  •  2
  •   Community CDub    8 年前

    您应该使用附加的命令行为模式。 This question 回答类似的问题,但在列表视图中。

    推荐文章