<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组第一题(8.9)

    2297. [noip普及组2(放到第一题)]棋盘 (好像重名了)(File IO): input:chess.in output:chess.out 题目描述 众所周知,国际象棋的棋盘是一个网格.国 ...

  2. Bugku-CTF之前女友(SKCTF)

    Day35    前女友(SKCTF) http://123.206.31.85:49162/ flag格式:SKCTF{xxxxxxxxxxxxxxxxxx}  

  3. Linux netstat命令详解(检验本机各端口的网络连接情况)

    netstat命令用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况.netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP ...

  4. 快递查询API

    https://market.aliyun.com/products/56928004/cmapi014394.html#sku=yuncode839400000

  5. LPR-贷款市场报价利率

    贷款市场报价利率(Loan Prime Rate)介绍: 贷款市场报价利率(Loan Prime Rate,简称LPR)是商业银行对其最优质客户执行的贷款利率,其他贷款利率可在此基础上加减点生成.贷款 ...

  6. linux 配置LVM

    1. 阿里云挂载LVM目录(创建LVM,以及配置第一块硬盘) fdisk /dev/vdb 输入 n p 1 enter enter wq pvcreate /dev/vdb1 vgcreate lv ...

  7. vue中watch和computed为什么能监听到数据的改变以及不同之处

    先来个流程图,水平有限,凑活看吧-_-|| 首先在创建一个Vue应用时: var app = new Vue({ el: '#app', data: { message: 'Hello Vue!' } ...

  8. Linux下查看当前文件大小的命令

    1.ls -lht 列出每个文件的大小和当前目录所有文件大小总和 2.du -sh * 列出当前文件夹下的所有子文件的大小 看你需要啥样的,自己来吧

  9. wordpress 代码获得菜单的方法

    1.第一种,在function.php中添加这个东东,wp_nav_menu()主要是用这个函数 $menu = 'menu'; $nav_menu = wp_get_nav_menu_object( ...

  10. acwing练习

    220. 最大公约数 给定整数N,求1<=x,y<=N且GCD(x,y)为素数的数对(x,y)有多少对. GCD(x,y)即求x,y的最大公约数. 输入格式 输入一个整数N 输出格式 输出 ...