How to navigate to other page with button in WPF

后端 未结 7 1714
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 15:56

I have a second .xaml page set up under the name Page2.xaml and I want to make it so that when my button is clicked, the user is taken to <

7条回答
  •  迷失自我
    2021-02-05 16:22

    Solution to my own question:

    I feel a bit silly providing a solution to my own question but thanks to Jasti's link I was able to sort my code out. As he had only posted a comment, I can't mark it as an answer, so here is the solution.

    I changed the NavigationWindow on to a Window and inserted:

    
        
    
    

    And within the constructor of the MainWindow.xaml.cs I added:

    _NavigationFrame.Navigate(new Page1());
    

    Then the last step was to adjust the button event handler to:

    this.NavigationService.Navigate(new Uri("Pages/Page2.xaml", UriKind.Relative));
    

提交回复
热议问题