简体   繁体   中英

How to navigate to another wpf page

So I tried to navigate to another wpf page but it doesn't work at all. Here's what I've been using:

C#:

    private void btnNext_Click(object sender, RoutedEventArgs e)
    {
        Doelen nextPage = new Doelen();
        this.NavigationService.Navigate(nextPage);
    }

XAML:

    <Button x:Name="btnNext" Content="Volgende" Margin="0,10,0,0" Click="btnNext_Click"/>

The big problem here is that Visual Studio says that there is no Navigate in NavigationService .

Can anyone tell me what I`m doing wrong?

For full code see picture below: 在此处输入图片说明

I would suggest using the this pointer and be explicit on your routedeventargs.

    using System.Windows.Navigation;

within:

public partial class MyPage : Page


private void btnNext_Click(object sender, System.Windows.RoutedEventArgs e)
{
    Doelen nextPage = new Doelen();
    NavigationService.Navigate(nextPage);
}
NavigationWindow nw = new NavigationWindow();
nw.Content = new Doelen();
nw.ShowDialog();

or nw.Show():

you may need a nw.Initialze();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM