了解WPF绑定CommandParameter =" {结合}" [英] Understand WPF Binding CommandParameter="{Binding}"

查看:360
本文介绍了了解WPF绑定CommandParameter =" {结合}"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是一个愚蠢的问题,但我无法找到答案:在下面的XAML是什么 CommandParameter 结合?或一般,什么是{}绑定意思?

 <按钮命令={结合DataContext.DeleteCommand,的ElementName =列表}
        CommandParameter ={结合}/>


解决方案

{绑定...} 是的MarkupExtension。结果
在其通常的形式,它需要像 A路径{结合路径= someProperty,...} (或其缩写形式 {结合someProperty,... } )。结果
因此,在路径{结合} 是空的,这意味着被绑定到任何来源没有为绑定。这可能是一个比较容易理解,如果你知道, {结合} 实际上是为 {结合的DataContext相同,的RelativeSource = {的RelativeSource自} }

所以你的情况CommandParameter获取按钮的当前的DataContext的价值。

Maybe this is a dumb question, but I can't find the answer: in the following xaml what does CommandParameter binding to? Or in general, what does "{Binding}" mean?

<Button Command="{Binding DataContext.DeleteCommand, ElementName=List}" 
        CommandParameter="{Binding}"/>

解决方案

{Binding ...} is a MarkupExtension.
In its usual form it takes a Path like {Binding Path=someProperty, ...} (or its short form {Binding someProperty, ...}).
So the path in {Binding} is empty which means the Binding is bound to whatever Source there is for the Binding. This might be a little easier to understand if you know, that {Binding} is actually the same as {Binding DataContext,RelativeSource={RelativeSource Self}}.

So in your case CommandParameter gets the value of the current DataContext of the Button.

这篇关于了解WPF绑定CommandParameter =&QUOT; {结合}&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆