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 ❘ 1037<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

code snippet BooksDemo/BookUC.xaml<br />

Within the OnShowBook() h<strong>and</strong>ler in the MainWindow.xaml.cs, create a new instance of the user control<br />

BookUC <strong>and</strong> add a new TabItem to the TabControl. Then change the SelectedIndex property of the<br />

TabControl to open the new tab:<br />

private void OnShowBook(object sender, RoutedEventArgs e)<br />

{<br />

var bookUI = new BookUC();<br />

this.tabControl1.SelectedIndex =<br />

this.tabControl1.Items.Add(<br />

new TabItem { Header = "Book", Content = bookUI });<br />

}<br />

code snippet BooksDemo/MainWindow.xaml.cs<br />

After building the project you can start the application <strong>and</strong> open the user control within the TabControl by<br />

clicking the hyperlink.<br />

binding with Xaml<br />

A WPF element can not only be the target for data binding, it can also be the source. You can bind the<br />

source property of one WPF element to the target of another WPF element.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!