WPF命令绑定

在WPF中有时候不想将命令写在List中,但是却要在前端绑定的List中写入命令
暂时知道两种解决方法
1、

 Command="{Binding DataContext.NavicateCommand, RelativeSource={RelativeSource AncestorType=ListView}}"

这是最常见的,AncestorType可以继续向外扩展为UserControl、Window
2、

 Command="{Binding DataContext.NavicateCommand,ElementName=xxx}"

将绑定的ListView或者ItemsControl的Name设置为xxx,通过ElementName绑定到命令

本文作者:孤沉

本文链接:https://www.cnblogs.com/guchen33/p/18034786

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   孤沉  阅读(46)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
展开