WPF Bind to itself

后端 未结 1 716
盖世英雄少女心
盖世英雄少女心 2020-12-13 03:20

I\'ve got a WPF Window, and somewhere there is a ListView where I bind a List to.

Now somewhere in my List

相关标签:
1条回答
  • 2020-12-13 03:42

    Short answer:{Binding} is not a shortcut for "binding to itself" (in the sense of RelativeSource.Self). Rather, {Binding} is equivalent to {Binding Path=.}, which binds to the current source.


    To elaborate: A binding has a source and a path. You can do a "binding to itself", for example, by using

    <myUIControl myProperty="{Binding RelativeSource={RelativeSource Self}, Path=x}" />
    

    This, however, sets the source to the control itself, so it will try to access property x of the UI control (rather than property x of the current data context). From how I understood your question, this is not what you want; in particular, it is not what {Binding} does: {Binding} keeps the source as it is (usually the DataContext of some parent element) and binds to the source itself (equivalent to Path=.).

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