此项目源码下载地址:https://github.com/lizhiqiang0204/TabControl-page-separation

每个页面的按键处理事件直接对应该页面下的cs文件

MainWindow.xaml文件如下

<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="" Width="">
<Grid>
<TabControl>
<TabItem Header="Page1">
<Frame Source="/WpfApp1;component/Pages/Page1.xaml"/>
</TabItem>
<TabItem Header="Page2">
<Frame Source="/WpfApp1;component/Pages/Page2.xaml"/>
</TabItem>
<TabItem Header="Page3">
<Frame Source="/WpfApp1;component/Pages/Page3.xaml"/>
</TabItem>
</TabControl>
</Grid>
</Window>

Page1.xaml文件如下:

<Page x:Class="WpfApp1.Pages.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1.Pages"
mc:Ignorable="d"
d:DesignHeight="" d:DesignWidth=""
Title="Page1"> <Grid>
<Button Click="Button_Click" Content="Page1" HorizontalAlignment="Left" Margin="213,124,0,0" VerticalAlignment="Top" Width="" />
</Grid>
</Page>

Page1.xaml.cs文件如下

namespace WpfApp1.Pages
{
/// <summary>
/// Page1.xaml 的交互逻辑
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
} private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("页面1按键事件!");
}
}
}

其他页面以此类推,整个运行结果界面如下

如果Page与Window之间有调用关系的话还需要进一步增加点内容,参考https://www.cnblogs.com/lizhiqiang0204/p/11713414.html

最新文章

  1. python爬虫学习(8) —— 关于4399的一个小Demo
  2. CSS3中DIV水平垂直居中-2(3)
  3. SQL Server中的事务日志管理(6/9):大容量日志恢复模式里的日志管理
  4. CCF真题之最优灌溉
  5. lintcode:形状工厂
  6. 【HtmlParser】HtmlParser使用
  7. Spring AOP (下)
  8. VS项目如何添加到svn
  9. 《Effective C++》:条款48:理解力template 元编程
  10. BestCoder Round #16
  11. oracle之sql语句优化
  12. Ubuntu系统上安装搜狗拼音输入法sogou
  13. 关于struts2 Could not find action or result错误
  14. LeetCode 548. Split Array with Equal Sum (分割数组使得子数组的和都相同)$
  15. Template基础
  16. Leetcode_128_Longest Consecutive Sequence
  17. HTML5为输入框添加语音输入功能
  18. Azure 中的虚拟网络和虚拟机
  19. 汇编 inc 和 dec 指令
  20. linux编程之pipe()函数

热门文章

  1. C#规范整理&#183;语言要素
  2. Elasticsearch 6.2.3版本 string 类型字段 排序 报错 Fielddata is disabled on text fields by default
  3. java:struts2.3框架1(struts2快速配置,各文件之间的关系,基础代码简化版,XML中的通配符)
  4. Golang基础(7):go的net/rpc用法
  5. CentOS 升级 openSSH+ sh脚本自动运维
  6. Day03:数组 、 继承的意义(上)
  7. 【神经网络与深度学习】【Matlab开发】caffe-windows使能Matlab2015b接口
  8. VMware下的Centos7联网并设置固定IP(nat)
  9. 关于add migration 报错的问题解决方案
  10. Android 透明主题