08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

200<br />

CHAPTER 8 ■ .<strong>NET</strong> 3.0: WINDOWS PRESENTATION FOUNDATION<br />

8. Select Address (Array) <strong>and</strong> click Finish. This sets the DataContext for the Grid (<strong>and</strong><br />

thus all its child controls) to the set of addresses that are found in the XML file.<br />

9. Next, add a TextBox, a Button, <strong>and</strong> a ListBox to the window. You are going to set up<br />

the data binding for the ListBox. Select it <strong>and</strong> look at its common properties. You<br />

will see that its DataContext property has already been initialized because the<br />

control is on the Grid that had its DataContext set, <strong>and</strong> the ListBox inherited this.<br />

You can of course override it <strong>and</strong> point to a different data source to get the context<br />

for this control, but for now, this is perfectly OK.<br />

10. To bind the ListBox to the data source, you use the ItemsSource property. Click it<br />

<strong>and</strong> select Data Binding in the ensuing dialog.<br />

11. The Create Data Binding dialog will appear. This time, you want to bind to the<br />

context that is already present, so select the Explicit Data Context tab <strong>and</strong> pick<br />

your data source from there. If you don’t see all the fields, change the Show dropdown<br />

to All Properties (see Figure 8-22).<br />

Figure 8-22. Binding to the current DataContext

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!