WPFwiki, wpf, wiki, .net 3.0, windows presentation foundation, FAQ, free resources, solution, development, microsoft Home of the world's largest WPF FAQ
Edit

Category

Data Binding

Edit

Question

What's the difference between ItemsSource, DataContext, Binding, and DataSourceProvider?

Edit

Answer

Obviously, these are all related to data binding ,but they play different roles. These concepts can be categorized into three groups.

Data definition
DataSourceProvider and its derived classes XmlDataProvider and ObjectDataProvider are used to define the data itself. They can be declared in code or in XAML (see related links). For instance, XmlDataProvider allows you to create an entire XML document in XAML that will serve as the data source of a binding.

Binding definition or description
Binding is a class that allows the description of a binding between a source and a target. It is the "glue" that links a data store, aka source (database, collection, etc.), with a data consumer, aka target (user interface, web service, etc.). A binding is always defined by four pieces of information: the data source, a field (or property) of the data source, the data target and a DependencyProperty of the target.

The DataContext class is used to define the "source" part of a binding. It is useful to share one binding source across multiple object and/or dependency properties.

Binding implementation
Most dependency properties can be assigned a binding, making use of the previously described concepts. However, objects are free to expose their own way of supporting binding.

The ItemsControl's ItemsSource property is a good example in that it expects a IEnumerable object and not the four components of Binding already explained.

Edit

Keywords

databinding

All content is Copyright ©2007 Xceed Software Inc. unless otherwise indicated. See the Terms of Service. Contributors must read and agree to the Contribution Policy. WPFwiki is brought to you by Xceed, makers of the powerful yet free Xceed DataGrid for WPF.