1. Open you Visual Studio 2010
2. Select File, New, Project and Select WPF Application
3. Click
Ok
 |
And your project will look like this. |
4. Go to
Toolbox (On the left side your)
add Frame and Button
 |
1 frame and 1 button. |
5. Right click
WpfApplication (your projects title) on right side of the project
Click
Add Then choose
Page
6. Choose
Page(WPF)
Name your Page.
Then Click Add
7. Add something or anything on your page.
Then go back to your MainWindow
8. Add this code on your XAML for Navigation
<Window.CommandBindings>
<CommandBinding Command="NavigationCommands.GoToPage" Executed="GoToPageExecuteHandler" CanExecute="GoToPageCanExecuteHandler" />
</Window.CommandBindings>
9. Double click the
button and add this code just after the
public MainWindow()
private void GoToPageExecuteHandler(object sender, ExecutedRoutedEventArgs e)
{
frame1.NavigationService.Navigate(new Uri((string)e.Parameter, UriKind.Relative));
}
private void GoToPageCanExecuteHandler(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
10. Right Click the button Go to page 1 and select Properties
Type GoToPage to Command
Page1.xaml (or the name of your page where you want to navigate) to CommandParameter
And on CommandTarget click the box or the advanced properties, Apply Data Binding
Choose Element Name, frame1 (or the title of your frame)
And that's it!
Now, press F5 to run your program.
 |
Running program.
After clicking the Go To Page 1 button. |
Read more...