要想在WPF窗体中实现不同页面切换,我们就需要用到ContentControl这个控件,这个控件的位置和大小就是你要显示页面的位置和大小。

下面举例说明:

Xaml:

    <Grid>
<Button Content="Page1" HorizontalAlignment="Left" Margin="21,20,0,0" VerticalAlignment="Top" Width="75" Height="30" Click="Button_Click"/>
<Button Content="Page2" HorizontalAlignment="Left" Margin="21,83,0,0" VerticalAlignment="Top" Width="75" Height="31" Click="Button_Click_1"/>
<Button Content="Page3" HorizontalAlignment="Left" Margin="21,149,0,0" VerticalAlignment="Top" Width="75" Height="30" Click="Button_Click_2"/>
<ContentControl x:Name="Page_Change" HorizontalAlignment="Left" Margin="127,20,0,0" VerticalAlignment="Top" Height="248" Width="511"/>
</Grid>

如图:

Page1:

Page2:

Page3:

后台代码:

        private void Button_Click(object sender, RoutedEventArgs e)
{
Page1 page1 = new Page1();
Page_Change.Content = new Frame()
{
Content = page1
};
} private void Button_Click_1(object sender, RoutedEventArgs e)
{
Page2 page2 = new Page2();
Page_Change.Content = new Frame()
{
Content = page2
};
} private void Button_Click_2(object sender, RoutedEventArgs e)
{
Page3 page3 = new Page3();
Page_Change.Content = new Frame()
{
Content = page3
};
}

运行效果:

可以实现多页面的切换,但是这里需要注意一个问题,Page页面的大小(长和宽)要和ContentControl的大小保持一致,才能够完全显示你页面里面的内容。

最新文章

  1. 获取Ca证书相关与服务器信息
  2. c++ 覆盖、重载与隐藏
  3. tortoiseSVN svn+ssh
  4. Spring4整合Hibernate4详细示例
  5. The usage method of reference with bibtex in Latex【latex中参考文献的使用方法】
  6. 什么是PWM、PFM及VFM
  7. jquery next nextAll nextUntil siblings的区别
  8. Linux下cut命令用法
  9. 最近跑hadoop遇到的一些问题
  10. SVN的学习以及使用!
  11. 使用GDB调试Android NDK native(C/C++)程序-转
  12. Python 任务队列 Celery
  13. 我的three.js学习记录(三)
  14. 认识Linux分区
  15. springaop问题——Cannot subclass final class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages
  16. ActiveMQ安装配置及实例
  17. springboot vue简单整合
  18. C#:进程
  19. ssh远程端口转发
  20. vuejs安装篇

热门文章

  1. java集合框架之Collection
  2. HTML学习笔记(一)HTML的一些概念区别
  3. E20190414-hm
  4. ObjectArx 中反应器Reactor的使用
  5. bzoj 1901: Zju2112 Dynamic Rankings【整体二分+树状数组||主席树+树状数组】
  6. PostgreSQL - 查询表结构和索引信息
  7. android studio ffmpeg简单使用 (cmake)
  8. activity fragment 传值
  9. vs 对网站和项目使用IIS Express 的64位版
  10. exec 和 eval