WPF 之 跳转

  WPF的跳转有两种:一是windows窗体,另外一种是page页。

  1、windows窗体跳转

  1)先实例化目标窗体;

  2)然后将目标窗体show()。

  例如:有两个窗体Main和Login,要想点击Login 窗体上的注册按钮然后跳转到Main上,则在Login窗体的Click事件里代码如下:

Main Mn=new Main();
Mn.Show();

2、Page页面跳转,前台跳转和后台跳转都可以实现

  1)前台跳转实现:

<TextBlockFontSize="24"TextWrapping="Wrap"Margin="0,0,0,0">
    <Hyperlinkx:Name="LnkPre"NavigateUri="Page1.xaml"Foreground="Black">
    Enter Page1
    </Hyperlink>
</TextBlock>

  后台实现:

NavigationService.GetNavigationService(this).Navigate(newUri("Page1.xaml", UriKind.Relative));
NavigationService.GetNavigationService(this).GoForward();//向后转
NavigationService.GetNavigationService(this).GoBack();  //向前转

  在后台还可以这样写:this.content = new Page1();(这种比较简单,但是建议大家使用前一种更能提高自己)

三、实现windows跳转到page:

NavigationWindow window =newNavigationWindow();
window.Source =newUri("Page1.xaml", UriKind.Relative);
window.Show();
原文地址:https://www.cnblogs.com/xinaixia/p/5512705.html