• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

how to navighate between XAML pages

P

Plamen Ratchev

#2
First, your pages have to be hosted in navigation container:
NavigationWindow or Frame. Next, you can use something like this:

// navigate to a page instance
MyPage next = new MyPage();
this.NavigationService.Navigate(next);

// navigate via URI
this.NavigationService.Navigate( new Uri("MyPage.xaml", UriKind.Relative));

You can also use hyperlinks or the journal.

HTH,

Plamen Ratchev
http://www.SQLStudio.com
 

My Computer

S

SenthilVel

#3
Hi ,
i also used the same method to navigate between pages, but when i hit the
ns.Navigate(myPage);

i get an error like ": use NEW keyword to create an object instance "....

canu let me know whats the Hotsed in Navigation container??

both of my pages have the build action as Pages..



Thanks

Senthil





I still get an error like
"Plamen Ratchev" <Plamen@SQLStudio.com> wrote in message
news:%232Q3rT1bHHA.3408@TK2MSFTNGP03.phx.gbl...
> First, your pages have to be hosted in navigation container:
> NavigationWindow or Frame. Next, you can use something like this:
>
> // navigate to a page instance
> MyPage next = new MyPage();
> this.NavigationService.Navigate(next);
>
> // navigate via URI
> this.NavigationService.Navigate( new Uri("MyPage.xaml",
> UriKind.Relative));
>
> You can also use hyperlinks or the journal.
>
> HTH,
>
> Plamen Ratchev
> http://www.SQLStudio.com
>
>
 

My Computer

P

Plamen Ratchev

#4
You must be missing something in your code. Try the following example:

// file: App.xaml
// Main application.

<Application x:Class="NavigationTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Container.xaml"
>

<Application.Resources>

</Application.Resources>
</Application>

// file: Container.xaml
// This is the NavigationWinodw that will host your pages.

<NavigationWindow x:Class="NavigationTest.Container"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="NavigationTest" Height="300" Width="300"
Source="Main.xaml"
>

</NavigationWindow>

// file: Main.xaml
// This is the main/default page.

<Page x:Class="NavigationTest.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Main"
>

<Grid>
<Button Click ="Next_Click" Content="Next" />
</Grid>
</Page>

// file: Main.xaml.cs
// Code to handle the button click which will navigate to next page.

namespace NavigationTest
{
public partial class Main : System.Windows.Controls.Page {
public Main() {
InitializeComponent();
}

private void Next_Click(object sender, RoutedEventArgs e) {
// This is where you create an instance of the next page and
navigate to it.
NextPage next = new NextPage();
this.NavigationService.Navigate(next);
}
}
}

// file: NextPage.xaml
// This is the next page that you will navigate to.

<Page x:Class="NavigationTest.NextPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="NextPage"
>

<Grid>
<TextBlock>This is the next page.</TextBlock>
</Grid>
</Page>



HTH,

Plamen Ratchev
http://www.SQLStudio.com
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)