这个做法是来自“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>
xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml%22>
public partial class PageSwitcher : UserControl
{
public PageSwitcher()
{
InitializeComponent();
SwitchPage(new Page()); //显示第一个要显示的页面
}
///
/// 切换页面
///
/// 需要被切换到的页面
public void SwitchPage(UserControl newPage)
{
this.Content = newPage;
}
}
{
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());
}
{
PageSwitcher switcher = this.Parent as PageSwitcher;
switcher.SwitchPage(new AnotherPage());
}
private void Application_Startup(object sender,StartupEventArgs e)
{
this.RootVisual = new PageSwitcher();
}
{
this.RootVisual = new PageSwitcher();
}
REF:http://www.cnblogs.com/Ricky81317/archive/2008/11/28/1342942.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。