<HierarchicalDataTemplate x:Key="TreeNodes" ItemsSource="{Binding Path=Childs,Mode=OneWay}" >
<StackPanel Orientation="Horizontal" Height="24" DataContext="{Binding}">
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="12" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding SelectCommand}"
CommandParameter="{Binding Id}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</StackPanel>

  按照button中binding 的方式書寫TreeView中的綁定,实际运行中将会没有想过,原因是TreeView中Command默认绑定的是TreeView的DataContext,实际只需要制定正确的Command的源即可。

<HierarchicalDataTemplate x:Key="TreeNodes" ItemsSource="{Binding Path=Childs,Mode=OneWay}" >
<StackPanel Orientation="Horizontal" Height="24" DataContext="{Binding}">
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="12" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding Path=DataContext.SelectCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Page}}}"
CommandParameter="{Binding Id}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</StackPanel>

  

TreeView 中 MVVM Command Binding的更多相关文章

  1. MVVM Command Binding: InvokeCommandAction v.s. EventToCommand

    This gives you the ability to create a trigger on an event and bind it to an ICommand on the view mo ...

  2. WPF中 MVVM模式的Slider Binding.

    对于Button的Command的绑定可以通过实现ICommand接口来进行,但是Slider并没有Command属性. 另外如果要实现MVVM模式的话,需要将一些Method和Slider的Even ...

  3. WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参

    原文:WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参 ContextMenu无论定义在.cs或.xaml文件中,都不继承父级的DataC ...

  4. WPF MVVM,Prism,Command Binding

    1.添加引用Microsoft.Practices.Prism.Mvvm.dll,Microsoft.Practices.Prism.SharedInterfaces.dll: 2.新建文件夹,Vie ...

  5. 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令

    [源码下载] 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 作者:webabcd ...

  6. 背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令

    [源码下载] 背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 作者:webabcd ...

  7. MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令

    介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 ...

  8. MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令

    介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 ...

  9. (WPF, MVVM) Slider Binding.

    对于Button的Command的绑定可以通过实现ICommand接口来进行,但是Slider并没有Command属性. 另外如果要实现MVVM模式的话,需要将一些Method和Slider的Even ...

随机推荐

  1. C#中使用IndexOf()判断字符串在字符串数组中第一次出现的索引位置

    ] {"}; "; //判断字符串的前几位在另一个字符串数组中第一次出现的索引位置 index = Array.IndexOf(s, s1.Substring(, ));

  2. 可以使用的一些API(转存)

    聚合数据 juhe.com 转存的格式不如原文的好看,可以直接访问原文 https://www.jianshu.com/p/9a0acf69b789 api接口应该会越来越火,上个全的,楼主自己找找吧 ...

  3. k8s默认存储动态挂载分配配置

    k8s默认存储动态挂载分配配置 k8s默认存储动态挂载分配配置 https://blog.csdn.net/BigData_Mining/article/details/96973871

  4. C9300升级-TFTP

    1.操作命令:CAT9300(config)#ip tftp blocksize 8192CAT9300(config)#install add file tftp://10.1.100.37/cat ...

  5. 数据库程序接口——JDBC——API解读第一篇——建立连接的核心对象

    结构图 核心对象 Driver Java通过Driver接口表示驱动,每种类型的数据库通过实现Driver接口提供自己的Driver实现类. Driver由属性,操作,事件三部分组成. 属性 公共属性 ...

  6. Codeforces Round #618 (Div. 1)B(几何,观察规律)

    观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...

  7. Jmeter 测试结果分析之聚合报告简介

    聚合报告(aggregate report) 对于每个请求,它统计响应信息并提供请求数,平均值,最大,最小值,错误率,大约吞吐量(以请求数/秒为单位)和以kb/秒为单位的吞吐量. 吞吐量是以取样目标点 ...

  8. Java switch的用法

    控制流程语句之→switch选择判断语句  注意事项: 1.多个case后面的值不能重复: 2.switch后面小括号当中只能是下列数据类型: 基本数据类型:byte.short.char.int 引 ...

  9. Plastic Bottle Manufacturer Profile: Plastic Bottle Forming Process

    Plastic bottle molding refers to the process of making a final plastic product from a polymer produc ...

  10. cookie的封装

    今天逛论坛,看到一个看起来写得好的函数,特此贴出分享: 原文地址[http://www.html-js.com/article/2638 ] 这个地址[https://github.com/jaywc ...