What does 'ItemsSource="{Binding}"' mean?
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 homework-level but I'm 开发者_如何学Ctrying to work out what existing XAML does, with an insufficient understanding of the concepts behind it...
Anyway, I have a ListView with this as part of its definition:
<ListView
DataContext="{StaticResource XMLFileGroups}"
ItemContainerStyle="{StaticResource XMLItemStyle}"
ItemsSource="{Binding}">
Now, I can kind of get my head around what the "DataContext" and "ItemContainerStyle" lines are doing; they appear to be referencing a method of sorting an existing list, and a structure defining some visual behaviour of the ListView, respectively.
What's wrecking me is the fact that the ItemsSource is listed as "{Binding}". All that says to me is that there is some kind of databinding in place, but I don't understand how the line can possibly be meaningful and yet removing it stops any data from being displayed.
Can someone shed some light on what is happening here, or where I should look for the actual binding definition? I just don't understand what I'm seeing, here.
Without a path, {Binding}
will bind to the DataContext
itself.
Adding a path will bind to a property of the datacontext.
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
精彩评论