如何在Silverlight中切换“页面”
2009-07-13 16:29
399 查看
这个做法是来自“Jesse Liberty”的视频“USING MULTIPLE PAGES, PART 1”,基本方法是创建一个PageSwticher,这个PageSwitcher不直接显示页面,而是作为一个后台,负责切换各个页面。 具体做法是: 新建一个UserControl,名字可以叫做PageSwitcher。然后将PageSwitcher.xaml中的Grid控件去掉,编程下面这样: <UserControl x:Class="SilverlightDemo.PageSwitcher"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22>
</UserControl> 然后在后台代码中增加一个方法,比如叫做SwitchPage,用来切换页面,然后在构造函数中调用,用来显示第一个要显示页面: public partial class PageSwitcher : UserControl
{
public PageSwitcher()
{
InitializeComponent();
SwitchPage(new Page()); //显示第一个要显示的页面
}
/// <summary>
/// 切换页面
/// </summary>
/// <param name="newPage">需要被切换到的页面</param>
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:/article/5184146.html
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22>
</UserControl> 然后在后台代码中增加一个方法,比如叫做SwitchPage,用来切换页面,然后在构造函数中调用,用来显示第一个要显示页面: public partial class PageSwitcher : UserControl
{
public PageSwitcher()
{
InitializeComponent();
SwitchPage(new Page()); //显示第一个要显示的页面
}
/// <summary>
/// 切换页面
/// </summary>
/// <param name="newPage">需要被切换到的页面</param>
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:/article/5184146.html
相关文章推荐
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- 如何在Silverlight中切换“页面”
- sharepoint开发中,页面报“未知错误”或“Unknown Error”后,如何查看详细错误信息
- 如何使用Ruby中的“split”方法
- Silverlight For WinEmbedded 的页面切换实现
- Silverlight外包公司--分享浅析在Silverlight中实现“页面”切换
- 如何解决Silverlight集成到IIS无法显示页面问题
- html页面如何实现中英文切换?
- silverlight中如何方便在多个"场景"即Xaml文件之间随意切换?(转)
- 如何建立和删除以“.”、“[空格]”结尾的文件夹
- 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面。
- 如何在Silverlight 页面上使用弹出层
- 如何在ASP.NET 项目中使用Silverlight页面
- 技巧:Silverlight应用程序中如何获取ASP.NET页面参数
- Silverlight页面切换方法
- Silverlight编译出错: 未给任务“CreateRiaClientFilesTask”的必需参数“ClientFrameworkPath”赋值
- Android Note 1 如何在不同页面间切换