public class NavigationPage
{
public string Name { get; set; }
public string Url { get; set; }
}
Submitted by Umesh Patel (March 18, 2009)
The Silverlight Navigation feature provides a rapid means of developing page-based web applications. The two primary controls in the System.Windows.Control.Navigation namespace are Frame and Page. The Frame control hosts a single Page control utilizes the Navigation APIs to allow the user to navigate between the pages. The Page control resembles the commonly used UserControl control to hold the contents of the respected page.
In this tutorial, we will show you to have create a quick Navigation Application.
The default project has two default pages (About and Home). To add additional pages, you can create pages using the Silverlight Page template and add the buttons to call them in MainPage.xaml We will extend this process by data binding the navigation links to a local xml file.
<navigation> <page name="Home" url="/Views/HomePage.xaml" /> <page name="About" url="/Views/AboutPage.xaml" /> </navigation>
public class NavigationPage
{
public string Name { get; set; }
public string Url { get; set; }
}
<StackPanel Style="{StaticResource NavigationPanelStyle}">
<Button Click="NavButton_Click" Tag="/Views/HomePage.xaml" Content="home" Style="{StaticResource PageLinkStyle}"/>
<Button Click="NavButton_Click" Tag="/Views/AboutPage.xaml" Content="about" Style="{StaticResource PageLinkStyle}"/>
</StackPanel>
Replace with the following code snippet.
<ItemsControl x:Name="listNavigation">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Style="{StaticResource NavigationPanelStyle}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Click="NavButton_Click" Tag="{Binding Url}" Content="{Binding Name}" Style="{StaticResource PageLinkStyle}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
XElement xml = XElement.Load("Navigation.xml");
List<NavigationPage> pages = (from page in xml.Elements("page")
select new NavigationPage
{
Name = (string)page.Attribute("name"),
Url = (string)page.Attribute("url")
}).ToList();
listNavigation.ItemsSource = pages;
SetPage(pages[0].Url);
}
<Grid Background="White">
<StackPanel>
<TextBlock Text="Links" Style="{StaticResource HeaderTextStyle}"/>
<HyperlinkButton Content="http://www.silverlighttoys.com" NavigateUri="http://www.silverlighttoys.com" Style="{StaticResource HyperlinkButtonStyle}"/>
</StackPanel>
</Grid>
<page name="Links" url="/Views/LinksPage.xaml" />
The Navigation Application feature can be used to develop rich, complete web applications. Web Browser interaction ensures that the end user get the traditional navigation flow as they traverse through the application.