TreeView 中 MVVM Command Binding
<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的更多相关文章
- 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 ...
- WPF中 MVVM模式的Slider Binding.
对于Button的Command的绑定可以通过实现ICommand接口来进行,但是Slider并没有Command属性. 另外如果要实现MVVM模式的话,需要将一些Method和Slider的Even ...
- WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参
原文:WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参 ContextMenu无论定义在.cs或.xaml文件中,都不继承父级的DataC ...
- WPF MVVM,Prism,Command Binding
1.添加引用Microsoft.Practices.Prism.Mvvm.dll,Microsoft.Practices.Prism.SharedInterfaces.dll: 2.新建文件夹,Vie ...
- 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令
[源码下载] 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 作者:webabcd ...
- 背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令
[源码下载] 背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 作者:webabcd ...
- MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令
介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 ...
- MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令
介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 ...
- (WPF, MVVM) Slider Binding.
对于Button的Command的绑定可以通过实现ICommand接口来进行,但是Slider并没有Command属性. 另外如果要实现MVVM模式的话,需要将一些Method和Slider的Even ...
随机推荐
- Bugku-web进阶之phpcmsV9(一个靶机而已,别搞破坏。flag在根目录里txt文件里)
phpcmsV9 一个靶机而已,别搞破坏. flag在根目录里txt文件里 http://123.206.87.240:8001/
- [单片机] ESP8266 开机自动透传
AT+CWMODE=1//设置WiFi工作在透传模式 AT+CWJAP_DEF="XX","YYY"//设置要链接的wifi名称.密码,并进行连接 //设置TC ...
- HDU 2586(LCA欧拉序和st表)
什么是欧拉序,可以去这个大佬的博客(https://www.cnblogs.com/stxy-ferryman/p/7741970.html)巨详细 因为欧拉序中的两点之间,就是两点遍历的过程,所以只 ...
- FILES源代码
FILESの源码 #include <bits/stdc++.h> #include <game.h> #define pause getchar(); #define c ...
- Linux上临时路由、永久路由配置
Linux下查看路由条目 查看路由表命令 route -n 示例 [root@cobbler_vm ~]# route -n Kernel IP routing table Destination G ...
- quernation,euler,rotationmatrix之间的相互转换
转自:https://blog.csdn.net/zhuoyueljl/article/details/70789472
- Python实现一个桌面版的翻译工具【新手必学】
Python 用了好长一段时间了,起初是基于对爬虫的兴趣而接触到的.随着不断的深入,慢慢的转了其它语言,毕竟工作机会真的太少了.很多技能长时间不去用,就会出现遗忘,也就有了整理一下,供初学者学习和 ...
- Cosmetic Bottles-Cosmetic Packaging Purpose: 5 Things
Packaging in the cosmetics industry is based on in-depth research. And how it helps to win the edge ...
- Linux动态库路径配置
参考链接:https://blog.csdn.net/blade2001/article/details/32839937 为什么要关注动态库路径配置,是因为工作中遇到动态库依赖其他动态库,而其他动态 ...
- java用JSONObject生成json
Json在前后台传输中,是使用最多的一种数据类型.json生成的方法有很多,自己只是很皮毛的知道点,用的时候,难免会蒙.现在整理下 第一种: import net.sf.json.JSONArray; ...