Understand WPF Binding CommandParameter=“{Binding}”

后端 未结 2 1302
闹比i
闹比i 2020-12-06 09:03

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 \"{Bind

相关标签:
2条回答
  • 2020-12-06 09:27

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

    0 讨论(0)
  • 2020-12-06 09:43

    {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.

    0 讨论(0)
提交回复
热议问题