WPF 体验---导航窗口
导航窗口是指带有导航工具的窗口。典型的win7窗体。
WPF 的导航窗体常见的有两种:Frame和NavigationWindow。
先看NavigationWindow:创建一个WPF Project,再添加一个Page.xaml。因为导航的内容大都基于Page的。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Navigation;
namespace WpfProject
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
NavigationWindow nw = new NavigationWindow();
nw.Content = new NovaGation.MainPage1();
nw.Show();
}
}
}
引用System.Windows.Navigation,创建对象,或者可以修改Window节点为NavigationWindow。
Frame,frame可以看作一个ContentControl,他的Content是一个Page。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<Window x:Class="WpfProject.NovaGation.FrameNova"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="FrameNova" Height="300" Width="300">
<StackPanel>
<TextBlock Background="BurlyWood" FontSize="15" FontWeight="25" Height="30" VerticalAlignment="Center">
<Hyperlink x:Name="homeHyper" Click="homeHyper_Click">Back to MainPage</Hyperlink>
</TextBlock>
<Frame Name="Frame1" Background="AliceBlue" Source="NaviPage2.xamll" NavigationUIVisibility="Visible" />
</StackPanel>
</Window>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfProject.NovaGation
{
/// <summary>
/// Interaction logic for FrameNova.xaml
/// </summary>
public partial class FrameNova : Window
{
public FrameNova()
{
InitializeComponent();
}
private void homeHyper_Click(object sender, RoutedEventArgs e)
{
this.Frame1.Navigate(new Uri("NovaGation\\MainPage1.xaml", UriKind.Relative));
}
}
}