< UserControl x:Class ="WPF_NavigationWindow.ApplicationToolbar" xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" Height ="Auto" Width ="Auto" >
< UserControl.Resources >
<!-- -->
< RoutedCommand x:Key ="NavigationCommand" />
</ UserControl.Resources >
< UserControl.CommandBindings >
<!-- -->
< CommandBinding Command ="{StaticResource NavigationCommand}" Executed ="NavigationCommand_Executed" />
</ UserControl.CommandBindings >
< ToolBar HorizontalAlignment ="Right" >
<!-- -->
< Button CommandParameter ="FirstPage.xaml" Command ="{StaticResource NavigationCommand}" > First Page </ Button >
< Button CommandParameter ="SecondPage.xaml" Command ="{StaticResource NavigationCommand}" > Second Page </ Button >
</ ToolBar >
</ UserControl >
* This source code was highlighted with Source Code Highlighter .
Thus, we have created a panel with buttons for navigating between pages. You can use a simpler solution - Hyperlink , let's add it to our control:< ToolBarPanel >
< TextBlock >
< Hyperlink NavigateUri ="FirstPage.xaml" > First Page </ Hyperlink >
< Hyperlink NavigateUri ="SecondPage.xaml" > Second Page </ Hyperlink >
</ TextBlock >
</ ToolBarPanel >
* This source code was highlighted with Source Code Highlighter .
So, as a result, we should get, approximately, the following view of the window:< Application x:Class ="WPF_NavigationWindow.App" xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri ="FirstPage.xaml" >
< Application.Resources >
< ResourceDictionary >
< ResourceDictionary.MergedDictionaries >
<!-- -->
< ResourceDictionary Source ="Themes/General.xaml" />
</ ResourceDictionary.MergedDictionaries >
</ ResourceDictionary >
</ Application.Resources >
</ Application >
* This source code was highlighted with Source Code Highlighter .
In the General.xaml file, we also need to include the resource file from the PresentationFramework.Aero library so that we can use the existing styles from the Aero theme in the style of our future NavigationManager. This is done in the same way:< ResourceDictionary.MergedDictionaries >
< ResourceDictionary Source ="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/Aero.NormalColor.xaml" />
</ ResourceDictionary.MergedDictionaries >
* This source code was highlighted with Source Code Highlighter .
Next, from the Style Explorer, copy the style for NavigationWindow, as well as its ContentTemplate (which is used in the style). We will slightly change the ContentTemplate, or rather add our ApplicationToolbar control to it, we will not do anything else. Note that links to the resources of the form ì, ď, ê remain and they will work. As a result, we should have, approximately, such a set of styles (most of them commented out, everything remains what the Style Explorer gave us):< ControlTemplate x:Key ="ď" TargetType ="{x:Type NavigationWindow}" >
< Border Background ="{TemplateBinding Control.Background}" BorderBrush ="{TemplateBinding Control.BorderBrush}" BorderThickness ="{TemplateBinding Control.BorderThickness}" >
< DockPanel >
< Grid Name ="NavChrome" Background ="{StaticResource ê}" DockPanel . Dock ="Top" Height ="30" >
< Grid.ColumnDefinitions >
< ColumnDefinition Width ="29" />
< ColumnDefinition Width ="26" />
< ColumnDefinition Width ="17" />
< ColumnDefinition Width ="*" />
</ Grid.ColumnDefinitions >
<!-- ... -->
<!-- -->
< WPF_NavigationWindow:ApplicationToolbar Grid . Row ="0" Grid . Column ="3" HorizontalAlignment ="Right" />
</ Grid >
<!-- ... -->
</ DockPanel >
</ Border >
< ControlTemplate.Triggers >
<!-- ... -->
</ ControlTemplate.Triggers >
</ ControlTemplate >
< Style x:Key ="{x:Type NavigationWindow}" TargetType ="{x:Type NavigationWindow}" >
<!-- ... -->
</ Style >
* This source code was highlighted with Source Code Highlighter .
As a result, our application will look like this:Source: https://habr.com/ru/post/63767/
All Articles