Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'ItemsSource="{Binding}"' mean?

Tags:

.net

wpf

xaml

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

like image 689
Frosty840 Avatar asked Oct 06 '10 15:10

Frosty840


People also ask

What do you mean by data binding?

Data binding is the process that establishes a connection between the app UI and the data it displays. If the binding has the correct settings and the data provides the proper notifications, when the data changes its value, the elements that are bound to the data reflect changes automatically.

What is ItemsSource in WPF?

ItemsSource can be data bound to any sequence that implements the IEnumerable interface, although the type of collection used does determine the way in which the control is updated when items are added to or removed. When ItemsSource is set, the Items property cannot be used to control the displayed values.

What is two way binding in WPF?

Two way binding is used when we want to update some controls property when some other related controls property change and when source property change the actual control also updates its property.

How do I fix XAML binding failures?

To enable this experience, go to “Options > Environment > Preview Features”, “XAML Binding Failure Window” and restart Visual Studio.


1 Answers

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

like image 166
SLaks Avatar answered Sep 23 '22 00:09

SLaks