WPF 多个选项卡TabControl 页面分离
2024-09-05 15:57:08
此项目源码下载地址: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
最新文章
- python爬虫学习(8) —— 关于4399的一个小Demo
- CSS3中DIV水平垂直居中-2(3)
- SQL Server中的事务日志管理(6/9):大容量日志恢复模式里的日志管理
- CCF真题之最优灌溉
- lintcode:形状工厂
- 【HtmlParser】HtmlParser使用
- Spring AOP (下)
- VS项目如何添加到svn
- 《Effective C++》:条款48:理解力template 元编程
- BestCoder Round #16
- oracle之sql语句优化
- Ubuntu系统上安装搜狗拼音输入法sogou
- 关于struts2 Could not find action or result错误
- LeetCode 548. Split Array with Equal Sum (分割数组使得子数组的和都相同)$
- Template基础
- Leetcode_128_Longest Consecutive Sequence
- HTML5为输入框添加语音输入功能
- Azure 中的虚拟网络和虚拟机
- 汇编 inc 和 dec 指令
- linux编程之pipe()函数
热门文章
- C#规范整理&#183;语言要素
- Elasticsearch 6.2.3版本 string 类型字段 排序 报错 Fielddata is disabled on text fields by default
- java:struts2.3框架1(struts2快速配置,各文件之间的关系,基础代码简化版,XML中的通配符)
- Golang基础(7):go的net/rpc用法
- CentOS 升级 openSSH+ sh脚本自动运维
- Day03:数组 、 继承的意义(上)
- 【神经网络与深度学习】【Matlab开发】caffe-windows使能Matlab2015b接口
- VMware下的Centos7联网并设置固定IP(nat)
- 关于add migration 报错的问题解决方案
- Android 透明主题