, "MainPage.xaml", System.Windows.Controls.Navigation. RootVisual ; , :
<navigation:Page
x:Class="Client.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignWidth="400"
d:DesignHeight="400" MinWidth="700" MinHeight="480"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Title="Main SlideLinc Page">
<Grid x:Name="LayoutRoot">
<navigation:Frame x:Name="rootFrame" />
</Grid>
</navigation:Page>
"rootFrame" , , NavigationManager:
public static void Navigate(string url, Action<Exception, UIElement> callback)
{
Navigate(new Uri(url, UriKind.RelativeOrAbsolute), callback);
}
public static void Navigate(Uri uri, Action<Exception, UIElement> callback)
{
if (rootFrame == null)
{
Logger.LogMessage("Can't use navigation, because rootFrame is null");
ErrorMessageBox.Show(ClientStrings.NavigationFailed);
}
else
{
NavigatedEventHandler successHandler = null;
NavigationFailedEventHandler failureHandler = null;
successHandler = (s, e) =>
{
rootFrame.Navigated -= successHandler;
rootFrame.NavigationFailed -= failureHandler;
if (callback != null)
{
callback(null, e.Content as UIElement);
}
};
failureHandler = (s, e) =>
{
rootFrame.Navigated -= successHandler;
rootFrame.NavigationFailed -= failureHandler;
if (callback != null)
{
callback(e.Exception, null);
}
};
rootFrame.Navigated += successHandler;
rootFrame.NavigationFailed += failureHandler;
rootFrame.Navigate(uri);
}
}
, :
NavigationManager.Navigate(new Uri("/Login.xaml", UriKind.Relative), null);
:
NavigationManager.Navigate(new Uri("/Home.xaml", UriKind.Relative), (error, element) => InitializeElement(element));