概念:
创建一个NavigationWindow,然后创建各个Page类,用navigationWindow的NavigationService来控制页面的切换
一、设置起始页为<NavigationWindow>
<NavigationWindow x:Class="DrumTeach.NaviWindow"
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:DrumTeach"
mc:Ignorable="d"
Source="Page_login.xaml"
Title="NaviWindow" AllowsTransparency="True" WindowStyle="None" WindowState="Normal" ResizeMode="NoResize" ShowsNavigationUI="False">
<!-- 这里不可加入任何东西,全部由this.NavigationService.Navigate(new Uri("pack://application:,,,/Page_CheckDevice.xaml"));来程序控制 -->
</NavigationWindow>
注意:
Source:为第一个Page页面
二、用WPF的页(Page)作为基类建立各页面
三、各页面内的跳转如下:
1、前进
if (this.NavigationService.CanGoForward)
{
this.NavigationService.GoForward();
}
else
{
//不能直接用Page_CheckDevice.xaml这个
this.NavigationService.Navigate(new Uri("pack://application:,,,/Page_CheckDevice.xaml"));
}
2、后退
this.NavigationService.GoBack();