
一、核心概念必考简答题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是独立顶层窗口。