如何在Silverlight中切换“页面”
2009-07-13 16:34
423 查看
这个做法是来自“Jesse Liberty”的视频“USING MULTIPLE PAGES, PART 1”,基本方法是创建一个PageSwticher,这个PageSwitcher不直接显示页面,而是作为一个后台,负责切换各个页面。
具体做法是:
新建一个UserControl,名字可以叫做PageSwitcher。然后将PageSwitcher.xaml中的Grid控件去掉,编程下面这样:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22>
然后在后台代码中增加一个方法,比如叫做SwitchPage,用来切换页面,然后在构造函数中调用,用来显示第一个要显示页面:
public partial class PageSwitcher : UserControl
{
public PageSwitcher()
{
InitializeComponent();
SwitchPage(new Page()); //显示第一个要显示的页面
}
///
/// 切换页面
///
/// 需要被切换到的页面
public void SwitchPage(UserControl newPage)
{
this.Content = newPage;
}
}
然后在我们的各个页面中,在需要切换页面的事件响应方法中,只需要这么做:
private void btn_Click(object sender, RoutedEventArgs e)
{
PageSwitcher switcher = this.Parent as PageSwitcher;
switcher.SwitchPage(new AnotherPage());
}
最后,我们需要修改app.xaml.cs中的Application_Startup方法,修改起始页面
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new PageSwitcher();
}
REF:http://www.cnblogs.com/Ricky81317/archive/2008/11/28/1342942.html
具体做法是:
新建一个UserControl,名字可以叫做PageSwitcher。然后将PageSwitcher.xaml中的Grid控件去掉,编程下面这样:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22>
然后在后台代码中增加一个方法,比如叫做SwitchPage,用来切换页面,然后在构造函数中调用,用来显示第一个要显示页面:
public partial class PageSwitcher : UserControl
{
public PageSwitcher()
{
InitializeComponent();
SwitchPage(new Page()); //显示第一个要显示的页面
}
///
/// 切换页面
///
/// 需要被切换到的页面
public void SwitchPage(UserControl newPage)
{
this.Content = newPage;
}
}
然后在我们的各个页面中,在需要切换页面的事件响应方法中,只需要这么做:
private void btn_Click(object sender, RoutedEventArgs e)
{
PageSwitcher switcher = this.Parent as PageSwitcher;
switcher.SwitchPage(new AnotherPage());
}
最后,我们需要修改app.xaml.cs中的Application_Startup方法,修改起始页面
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new PageSwitcher();
}
REF:http://www.cnblogs.com/Ricky81317/archive/2008/11/28/1342942.html
相关文章推荐
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- Android 如何在屏幕切换的时候页面信息不被重置
- 如何将HTML或aspx页面嵌入到Silverlight中
- silverlight 页面切换
- 如何自定义silverlight的加载页面
- Silverlight应用程序中如何获取ASP.NET页面参数
- Silverlight Style (一) 如何在页面应用样式
- 如何解决setInterval 与页面切换问题
- 技巧:Silverlight应用程序中如何获取ASP.NET页面参数 推荐
- 如何在Silverlight应用程序中获取ASP.NET页面参数
- asp.net页面如何调用silverlight
- 如何实现同一个页面里面两个页面的相互切换(window.onscroll)
- sencha 2.0 mvc框架中如何切换页面(switch view)
- 页面中Div之间如何进行切换???
- Silverlight For WinEmbedded 的页面切换实现
- Android 如何保证App切换到后台,或页面跳转后,重新打开APP、或返回之前页面时,维持其状态不变