How to click a button of the page to change the source of the frame of Windows?

后端 未结 1 658
粉色の甜心
粉色の甜心 2020-12-30 16:19

I have a WPF project, I add a frame in the Windows,the source of the frame is the page. I want to achieve clicking a button in the page to change the page of the frame.

1条回答
  •  星月不相逢
    2020-12-30 17:11

    EDIT: A functional solution can look like:

    MainWindow XAML:

    
                   
        
    
    
    

    MainWindow cs:

     frmMainContent.Source = new Uri("test1.xaml", UriKind.Relative); // initialize frame with the "test1" view
    

    test1 XAML:

    
        
    
    

    test1 cs:

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            NavigationService ns = NavigationService.GetNavigationService(this);
            ns.Navigate(new Uri("test2.xaml", UriKind.Relative));
        }
    

    test2 XAML:

      
            
        
    

    test2 cs:

     NavigationService ns = NavigationService.GetNavigationService(this);
                ns.Navigate(new Uri("test1.xaml", UriKind.Relative));
    

    This is a working solution using NavigationService.

    0 讨论(0)
提交回复
热议问题