What does 'ItemsSource=“{Binding}”' mean?

后端 未结 2 636
后悔当初
后悔当初 2020-12-28 12:22

I\'m attempting to learn WPF by unravelling a frankly nightmarish project written by the guy who was in this job before me. Sorry if some of my questions are pretty much hom

相关标签:
2条回答
  • 2020-12-28 13:00

    Without a path, {Binding} will bind to the DataContext itself.
    Adding a path will bind to a property of the datacontext.

    0 讨论(0)
  • 2020-12-28 13:14

    That example specifies that the binding is the DataContext. The same thing in the code behind would be

    MyList.ItemsSource = new Binding();
    

    You can also do stuff like:

    ItemsSource="{Binding YourBindingField, Source={StaticResource YourStaticDataSource}}"
    

    which would translate to this in code behind:

            MyList.ItemsSource = new Binding() {ElementName = "YourBindingField", Source = YourStaticDataSource};
    

    Hope that helps

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