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.

1098 ❘ ChaPTer 38 silverliGht<br />

To see navigation in action, create a new Visual Studio 2010 project of type Silverlight Navigation<br />

Application, named EventRegistration. This project template contains predefined styles, a main page,<br />

<strong>and</strong> a few pages in the Views folder that are navigated to.<br />

MainPage.xaml contains a Frame element. This element is prefixed with the navigation alias, which<br />

references the .<strong>NET</strong> namespace System.Windows.Controls in the assembly System.Windows.Controls<br />

.Navigation. Another alias that is used here is uriMapper, which references the .<strong>NET</strong> namespace System<br />

.Windows.Navigation in the same assembly. The Frame element is used as a parent of the different pages.<br />

The first page that is loaded is changed from the default to the /Welcome page by setting the Source<br />

property. The UriMapper class converts a URI to an object. So instead of specifying /Views/Welcome.xaml<br />

as the navigation source page, just /Welcome is enough <strong>and</strong> is translated to the Welcome.xaml file in the<br />

Views directory.<br />

All the styles that are referenced here are defined as resources in the file Styles.xaml file. This file is added<br />

to the application resource files in the file App.xaml.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

code snippet WCFRegistration/MainPage.xaml<br />

MainPage.xaml contains a logo <strong>and</strong> application name section as well as HyperlinkButton controls to<br />

let the user navigate between the main pages of the application. The logo is specified with the resource<br />

LogoIcon, which is defined with a Path element in the file Styles.xaml. The style of the HyperlinkButton<br />

elements is also defined in the styles file. The NavigateUri property is set to a Uri that is mapped with the<br />

UriMapper definitions shown earlier.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!