When to use Path in WPF Binding?

后端 未结 1 832
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 10:26

I\'ve seen a lot of WPF Binding examples and have used the feature in a lot of different places in learning MVVM, but something that has seemed quite inconsistent to me is w

相关标签:
1条回答
  • 2020-12-10 10:44

    There is no functional difference. The default property of the Binding object is Path, this means if you don't specify which property you are setting then you will set Path.

    This is because the Binding object has two constructors, one default and one that takes in a single string parameter. When you pass in a value without labeling it that property will be forwarded onto the matching constructor, in the case of Binding this sets the path. It is very similar in concept to the way attributes work, a call to the constructor followed by optional parameters, for example:

    [AttributeUsage(AttributeTargets.Class), AllowMultiple = false, Inherited = false ]
    

    Probably way beyond what you're actually asking the question for, but I've noticed that there is a slight (and probably inconsequential) difference between the two. Since I can't explain it myself I've started a new question about it here.

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