WPF页面跳转

来源:互联网 发布:信息技术考试操作题vb 编辑:程序博客网 时间:2024/04/29 21:06

WPF页面跳转有两种:一种是windows,另外一种是page 

1:windows页面跳转
windows 页面跳转相信学过winform编程的哥们都知道,先实例化该窗体然后show一下就可以了.eg:有两个窗体Main和Login,要想点击Login 窗体上的注册按钮然后跳转到Main上,则在Login窗体的Click事件里代码如下:Main Mn=new Main();Mn.Show();
2:Page页面跳转Page页面跳转:前台跳转和后台跳转都可以实现前台实现:

<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(new Uri("Page1.xaml", UriKind.Relative));

NavigationService.GetNavigationService(this).GoForward();//向后转

NavigationService.GetNavigationService(this).GoBack();  //向前转

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

NavigationWindow window =new  NavigationWindow();

window.Source =new  Uri("Page1.xaml", UriKind.Relative);

window.Show();