15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Data Binding ❘ 1043<br />

publisher = value;<br />

if (PropertyChanged != null)<br />

PropertyChanged(this, new PropertyChangedEventArgs(<br />

“Publisher”));<br />

}<br />

}<br />

private string isbn;<br />

public string Isbn {<br />

get<br />

{<br />

return isbn;<br />

}<br />

set<br />

{<br />

isbn = value;<br />

if (PropertyChanged != null)<br />

PropertyChanged(this, new PropertyChangedEventArgs("Isbn"));<br />

}<br />

}<br />

private readonly List authors = new List();<br />

public string[] Authors<br />

{<br />

get<br />

{<br />

return authors.ToArray();<br />

}<br />

}<br />

}<br />

}<br />

public override string ToString()<br />

{<br />

return this.title;<br />

}<br />

code snippet BooksDemo/Data/Book.cs<br />

With this change, the application can be started again to verify that the user interface gets an update from<br />

the change in the event h<strong>and</strong>ler.<br />

object data Provider<br />

Instead of instantiating the object in code-behind, you can do this with XAML. To reference a class from<br />

code-behind within XAML, you have to reference the namespace with the namespace declarations in the<br />

XML root element. The XML attribute xmlns:local=“clr-namespace:Wrox.ProCsharp.WPF” assigns<br />

the .<strong>NET</strong> namespace Wrox.ProCSharp.WPF to the XML namespace alias local.<br />

One object of the Book class is now defined with the Book element inside the DockPanel resources. By<br />

assigning values to the XML attributes Title, Publisher, <strong>and</strong> Isbn, you set the values of the properties<br />

from the Book class. x:Key=“theBook” defines the identifier for the resource so that you can reference the<br />

book object:<br />

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

Saved successfully!

Ooh no, something went wrong!