19.5. Data Providers

In most of the examples you've seen, the top-level data source has been supplied by programmatically setting the DataContext of an element or the ItemsSource property of a list control. In general, this is the most flexible approach, particularly if your data object is constructed by another class (such as StoreDB). However, you have other options.

One technique is to define your data object as a resource in your window (or some other container). This works well if you can construct your object declaratively, but it makes less sense if you need to connect to an outside data store (such as a database) at runtime. However, some developers still use this approach (often in a bid to avoid writing event handling code). The basic ...

Get Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.