首页
/
行业洞察
/
正文
INDUSTRY INSIGHT · 深度
WPF导航窗体+Page页面跳转 知识点整理
📅 2026/10/30 6:30:06
✍️ 爱科研究院
👁 阅读 3,247
一、核心概念必考简答题1. Window 与 NavigationWindow 区别普通Window只能弹出新窗口不具备页面导航功能无法内嵌Page页面切换。NavigationWindow导航窗体专门用于承载 Page 页面支持页面无刷新跳转、前进后退导航。2. WPF层级关系Application应用程序 → NavigationWindow导航窗口 → Page页面一个导航窗口可以嵌套多个Page页面实现单窗口多页面切换网页式效果。二、主导航窗口 NavigationWindowMainWindow核心属性考点Sourcexxx.xaml窗口启动默认加载的第一个Page页面ShowsNavigationUIFalse隐藏系统自带的前进/后退导航箭头NavigationWindow x:Class_2导航窗体.MainWindow xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml xmlns:dhttp://schemas.microsoft.com/expression/blend/2008 xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:localclr-namespace:_2导航窗体 mc:Ignorabled SourcePages/MainPage.xaml Title导航主窗口 Height450 Width800 ShowsNavigationUIFalse !-- ShowsNavigationUIFalse 隐藏系统默认导航栏箭头 -- /NavigationWindow三、主页页面 MainPage.xaml跳转入口知识点WrapPanel自动换行布局控件横向排列自动换行TextDecorations文本装饰线样式Strikethrough删除线Underline下划线MouseLeftButtonDown文本鼠标左键按下跳转页面Page x:Class_2导航窗体.Pages.MainPage xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:dhttp://schemas.microsoft.com/expression/blend/2008 xmlns:localclr-namespace:_2导航窗体.Pages mc:Ignorabled d:DesignHeight450 d:DesignWidth800 Title主页 Grid StackPanel TextBlock FontSize20 主页面 /TextBlock WrapPanel Margin20 !-- 删除线文本点击跳转Page1 -- TextBlock ForegroundGreen FontSize18 MouseLeftButtonDownTextBlock_MouseLeftButtonDown TextDecorationsStrikethrough 跳转 Page1 /TextBlock !-- 下划线文本点击跳转Page2 -- TextBlock Margin10,0 FontSize18 ForegroundGreen MouseLeftButtonDownTextBlock_MouseLeftButtonDown_1 TextDecorationsUnderline 跳转 Page2 /TextBlock /WrapPanel /StackPanel /Grid /Page四、子页面 Page1.xaml带返回按钮Page x:Class_2导航窗体.Pages.Page1 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:dhttp://schemas.microsoft.com/expression/blend/2008 xmlns:localclr-namespace:_2导航窗体.Pages mc:Ignorabled d:DesignHeight450 d:DesignWidth800 TitlePage1 Grid StackPanel VerticalAlignmentCenter HorizontalAlignmentCenter TextBlock FontSize22 Margin0,0,0,20 Page1 页面 /TextBlock Button ClickButton_Click Width100 Height100 BackgroundRed ForegroundWhite 返回主页 /Button /StackPanel /Grid /Page五、子页面 Page2.xaml纯展示页面Page x:Class_2导航窗体.Pages.Page2 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:dhttp://schemas.microsoft.com/expression/blend/2008 xmlns:localclr-namespace:_2导航窗体.Pages mc:Ignorabled d:DesignHeight450 d:DesignWidth800 TitlePage2 Grid TextBlock FontSize22 VerticalAlignmentCenter HorizontalAlignmentCenter Page2 页面 /TextBlock /Grid /Page六、全套后台C#导航逻辑核心考点6.1 MainPage 页面跳转后台using System.Windows; using System.Windows.Input; using System.Windows.Controls; namespace _2导航窗体.Pages { public partial class MainPage : Page { public MainPage() { InitializeComponent(); } // 跳转 Page1 private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // 导航到指定页面 this.NavigationService.Navigate(new Page1()); } // 跳转 Page2 private void TextBlock_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e) { this.NavigationService.Navigate(new Page2()); } } }6.2 Page1 返回主页后台using System.Windows; using System.Windows.Controls; namespace _2导航窗体.Pages { public partial class Page1 : Page { public Page1() { InitializeComponent(); } // 返回上一页 / 主页 private void Button_Click(object sender, RoutedEventArgs e) { // 判断是否可以返回 if (this.NavigationService.CanGoBack) { this.NavigationService.GoBack(); } } } }七、导航核心类与方法必背NavigationService页面导航核心服务类Navigate(new 页面名())跳转新页面GoBack()返回上一页CanGoBack判断是否存在上一页防止报错八、文本装饰线枚举Strikethrough删除线Underline下划线Overline上划线九、期末简答题汇总1. NavigationWindow 和 Window 的区别Window是普通窗口无法嵌套页面NavigationWindow是导航专用窗口支持Page页面跳转、导航堆栈适合单页面应用。2. NavigationService 常用方法Navigate跳转页面、GoBack返回上一页、CanGoBack判断是否可返回。3. ShowsNavigationUI 属性作用设置为False可以隐藏系统自带的前进后退箭头自定义页面导航样式。4. Page和Window区别Page无独立窗口标题栏必须依托NavigationWindow承载Window是独立顶层窗口。
📌 标签:
工业官网
设计趋势
AI 建站
SEO
获取完整报告 →
RELATED ARTICLES
推荐阅读
2026/10/30 6:30:06
OpenSpeedy游戏变速器完全指南:Ring3 Hook原理、三步上手与快捷键配置
2026/10/30 6:25:06
实时渲染、离线渲染、云渲染、混合渲染选型:从约束到决策
2026/10/30 6:25:06
49-常用类-Math类
2026/10/30 11:41:17
AdminLTE-3.1.0 实战指南:快速搭建后台管理系统与避坑技巧
2026/10/30 11:41:17
深度学习与光学物理交叉创新:计算机视觉摄影技术突破
2026/10/30 11:41:17
YOLO目标检测算法原理与工业实践指南
2026/10/30 11:41:17
AI架构中的伦理框架:从理论到实践的关键路径
2026/10/30 11:41:17
Vue 集成 bpmn.js:构建可编辑业务流程图与 XML 读写
2026/10/30 11:36:15
SCORM课件开发实战:从打包到运行时接口的完整指南
2026/10/30 0:03:44
OpenShell 完全定制指南:从安装到深度配置,打造高效 Windows 开始菜单
2026/10/30 0:03:44
Superpowers技能体系全解析:从Skills引入到安装的完整指南
2026/10/30 0:03:44
TensorFlow实现Weibull生存模型预测债券违约概率
2026/10/29 21:03:42
全国计算机二级C语言真题PDF高效刷题指南
2026/10/29 21:03:35
requests+BeautifulSoup:爬虫抓取h1标题的入门实战指南
2026/10/29 21:03:28
递推最小二乘参数辨识MATLAB编程:二阶系统与渐消记忆实现
2026/10/30 3:44:27
我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频
2026/10/30 3:44:25
Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证
2026/10/30 3:44:29
2026 大模型集体涨价:用 Python 做企业 Token 成本测算与选型避坑(附配置)