WPF窗口跳转及window和page区别
2011-03-30 14:31
441 查看
刚接触WPF,有两个概念不是很懂,现理解如下:
1:window和page谁包含谁的问题
一新建WPF应用程序,发现默认启动界面是一个window,将默认启动改为page,没有错误。但是如果在page中执行如下程序报错:
this.content = new Window1();
错误信息是:window是在属性结构的根目录。那么,我们可以理解为,window包含page,而不是反之。
2:登录界面(窗口跳转)
既然WPF的默认启动界面是一个窗口window,那么我也默认理解整个应用程序最上层最好是一个window(虽然全部是page也不会出错)。这大概是习惯使然,因为老的winform程序嘛,大家都是window。
那么,涉及到登录,就有个窗口之间的跳转,貌似没有好的方法,只能在登录的window中:
view plaincopy to clipboardprint?
WinMain wm = new WinMain();
wm.Show();
wm.WindowState = WindowState.Maximized;
this.Close();
WinMain wm = new WinMain();
wm.Show();
wm.WindowState = WindowState.Maximized;
this.Close();
3:页面跳转(page跳转)
前台转:
view plaincopy to clipboardprint?
<TextBlock FontSize="24" TextWrapping="Wrap" Margin="0,0,0,-19.998">
<Hyperlink x:Name="LnkPre" NavigateUri="Page2.xaml" Foreground="Black">
Enter Page2
</Hyperlink>
</TextBlock>
<TextBlock FontSize="24" TextWrapping="Wrap" Margin="0,0,0,-19.998">
<Hyperlink x:Name="LnkPre" NavigateUri="Page2.xaml" Foreground="Black">
Enter Page2
</Hyperlink>
</TextBlock>
后台转:
view plaincopy to clipboardprint?
NavigationService.GetNavigationService(this).Navigate(new Uri("Page2.xaml", UriKind.Relative));
NavigationService.GetNavigationService(this).GoForward();向后转
NavigationService.GetNavigationService(this).GoBack(); 向前转
NavigationService.GetNavigationService(this).Navigate(new Uri("Page2.xaml", UriKind.Relative));
NavigationService.GetNavigationService(this).GoForward();向后转
NavigationService.GetNavigationService(this).GoBack(); 向前转
在后台跳转中,还有一个更简单的用法是:
this.content = new Page2();
4:windows跳转到page
view plaincopy to clipboardprint?
NavigationWindow window = new NavigationWindow();
window.Source = new Uri("Page1.xaml", UriKind.Relative);
window.Show();
1:window和page谁包含谁的问题
一新建WPF应用程序,发现默认启动界面是一个window,将默认启动改为page,没有错误。但是如果在page中执行如下程序报错:
this.content = new Window1();
错误信息是:window是在属性结构的根目录。那么,我们可以理解为,window包含page,而不是反之。
2:登录界面(窗口跳转)
既然WPF的默认启动界面是一个窗口window,那么我也默认理解整个应用程序最上层最好是一个window(虽然全部是page也不会出错)。这大概是习惯使然,因为老的winform程序嘛,大家都是window。
那么,涉及到登录,就有个窗口之间的跳转,貌似没有好的方法,只能在登录的window中:
view plaincopy to clipboardprint?
WinMain wm = new WinMain();
wm.Show();
wm.WindowState = WindowState.Maximized;
this.Close();
WinMain wm = new WinMain();
wm.Show();
wm.WindowState = WindowState.Maximized;
this.Close();
3:页面跳转(page跳转)
前台转:
view plaincopy to clipboardprint?
<TextBlock FontSize="24" TextWrapping="Wrap" Margin="0,0,0,-19.998">
<Hyperlink x:Name="LnkPre" NavigateUri="Page2.xaml" Foreground="Black">
Enter Page2
</Hyperlink>
</TextBlock>
<TextBlock FontSize="24" TextWrapping="Wrap" Margin="0,0,0,-19.998">
<Hyperlink x:Name="LnkPre" NavigateUri="Page2.xaml" Foreground="Black">
Enter Page2
</Hyperlink>
</TextBlock>
后台转:
view plaincopy to clipboardprint?
NavigationService.GetNavigationService(this).Navigate(new Uri("Page2.xaml", UriKind.Relative));
NavigationService.GetNavigationService(this).GoForward();向后转
NavigationService.GetNavigationService(this).GoBack(); 向前转
NavigationService.GetNavigationService(this).Navigate(new Uri("Page2.xaml", UriKind.Relative));
NavigationService.GetNavigationService(this).GoForward();向后转
NavigationService.GetNavigationService(this).GoBack(); 向前转
在后台跳转中,还有一个更简单的用法是:
this.content = new Page2();
4:windows跳转到page
view plaincopy to clipboardprint?
NavigationWindow window = new NavigationWindow();
window.Source = new Uri("Page1.xaml", UriKind.Relative);
window.Show();
相关文章推荐
- WPF窗口跳转及window和page区别
- WPF窗口跳转及window和page区别
- WPF窗口跳转及window和page区别
- [转载]WPF窗口跳转及window和page区别
- WPF直接用Window.Close直接关闭窗口导致不能完全退出的问题
- WPF 中保存 window(窗口)或者canvas成图片
- WPF中设置了WindowStyle="None"后,窗口仍然有边框的解决方法
- WPF关闭应用程序,释放Window窗口资源方法
- 【WPF】分享自用 白板窗口(空窗口) 控件 BlankWindow,基于WindowChrome。
- window.location.href 框架子页面的引导--框架页顶层窗口跳转
- WPF 之 创建继承自Window 基类的自定义窗口基类
- [学习笔记]window.showModalDialog窗口跳转取值
- Response.Redirect跳转到另外的页面,并用新窗口打开(from:http://stackoverflow.com/questions/104601/asp-net-response-redirect-to-new-window)
- WPF:通过Window.DataContext实现窗口间传值
- WPF中的窗口的生命周期[window]
- WPF关闭应用程序,释放Window窗口资源方法
- WPF Window异形窗口演示
- WPF WindowChrome 自定义窗口
- WPF关闭应用程序,释放Window窗口资源方法
- WPF程序设计 :第一章 应用程序和窗口(The Application and the Window)