开发者

Understand WPF Binding CommandParameter="{Binding}"

Maybe this is a dumb question, but I can't find the answer: in the following xaml what does CommandParameter bindin开发者_高级运维g 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.


An Empty {Binding} will pass the current DataContext of the control to the Executed and CanExecute methods respectively.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜