There are tow main ways to navigate between pages: use hyperlinks and via code
Use hyperlinks
Just simply add HyperlinkButtons in your page.xaml file.
<HyperlinkButton Content="Page1" NavigateUri="/Page1.xaml" Height="30" HorizontalAlignment="Left" Margin="10,10,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="200" />
<HyperlinkButton Content="Page2" NavigateUri="/Page2.xaml" Height="30" HorizontalAlignment="Left" Margin="10,50,0,0" Name="hyperlinkButton2" VerticalAlignment="Top" Width="200" />
Via code
First, add Buttons in your page.xaml file.
<Button Content="Page1" Height="72" HorizontalAlignment="Left" Margin="10,120,0,0" Name="Page1" VerticalAlignment="Top" Width="160" Click="PageButton_Click" />
<Button Content="Page2" Height="72" HorizontalAlignment="Left" Margin="10,220,0,0" Name="Page2" VerticalAlignment="Top" Width="160" Click="PageButton_Click" />
Second, add the click event in your page.xaml.cs file.
private void PageButton_Click(object sender, RoutedEventArgs e)
{
Button clickedButton = (Button)sender;
switch (clickedButton.Name)
{
case "Page1":
NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
break;
case "Page2":
NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
break;
default:
break;
}
}
Additional Topics:
- Navigation Overview.
- Navigating and Passing Data between XAML Pages - Day 3 - Part 3.
- Navigation Between MainPage and ViewEdit Pages - Day 4 - Part 10.
- WP7 Development Tip of the Day: Page Startup: Loaded event vs. OnNavigatedTo method.
- Page navigation with values in SilverLight.
- Storing textbox value between pages.
No comments:
Post a Comment