Glossary Item Box
The Data Context is a new concept in Microsoft® Windows® Presentation Foundation, that works hand and hand with Data Binding to provide trees of elements with access to a specific set of data. When set on an element, the DataContext property (defined on FrameworkElement) provides a context for data binding on that element and all descendant elements. Any Binding statement that appears on these elements will use the specified DataContext to resolve the Binding's value.
For instance, if you have multiple controls on a page, and you want each control to bind to the same piece of data, you can set the DataContext property on an element that is an ancestor of all the controls (e.g., the root element of the Window), then specify bindings on properties of those controls that bind to specific pieces of data in the DataContext. When a DataContext is specified on an element, it serves as the context for data bindings on all descendant elements unless a new DataContext is set on a descendant element. In this case, the new DataContext will serve as the context for all the data bindings on that element and its descendants.
In this topic, we make use of an XmlDataProvider that we are going to assign to a xamDataGrid™, and a xamDataCarousel™.
In XAML:
xmlns:igDP="http://infragistics.com/DataPresenter"
In XAML:
<Page.Resources>
<XmlDataProvider Source="../Data/Orders.xml"
x:Key="OrderData" XPath="/Orders" />
</Page.Resources>
In XAML:
<StackPanel DataContext="{Binding Source={StaticResource OrderData}}">
<igDP:XamDataGrid x:Name="XamDataGrid1" DataSource="{Binding XPath=Order}"/>
<igDP:XamDataCarousel x:Name="XamDataCarousel1" DataSource="{Binding XPath=Order}"/>
</StackPanel>