Adding UWP project (instead of old Win8.1)
This commit is contained in:
Родитель
7d400cfc4c
Коммит
822eb34e32
|
@ -0,0 +1,154 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C97D386E-9CA0-4770-8AAC-C0A827B41501}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>GalaSoft.MvvmLight.Platform</RootNamespace>
|
||||
<AssemblyName>GalaSoft.MvvmLight.Platform</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.15063.0</TargetPlatformVersion>
|
||||
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
|
||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\GalaSoft.MvvmLight.Platform.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\GalaSoft.MvvmLight.Platform.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\ARM\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<OutputPath>bin\ARM\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\GalaSoft.MvvmLight.Platform.rd.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
<Version>5.2.3</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\GalaSoft.MvvmLight.Platform %28NET45%29\Properties\AssemblyInfo.cs">
|
||||
<Link>Properties\AssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\GalaSoft.MvvmLight.Platform %28NET45%29\Threading\DispatcherHelper.cs">
|
||||
<Link>Threading\DispatcherHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Views\DialogService.cs" />
|
||||
<Compile Include="Views\NavigationService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GalaSoft.MvvmLight %28PCL%29\GalaSoft.MvvmLight %28PCL%29.csproj">
|
||||
<Project>{6a912701-3ba1-4975-adbf-160caf66b640}</Project>
|
||||
<Name>GalaSoft.MvvmLight %28PCL%29</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="GalaSoft.MvvmLight.Platform %28UWP%29.snk" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>GalaSoft.MvvmLight.Platform %28UWP%29.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Двоичные данные
GalaSoft.MvvmLight/GalaSoft.MvvmLight.Platform (UWP)/GalaSoft.MvvmLight.Platform (UWP).snk
Normal file
Двоичные данные
GalaSoft.MvvmLight/GalaSoft.MvvmLight.Platform (UWP)/GalaSoft.MvvmLight.Platform (UWP).snk
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This file contains Runtime Directives, specifications about types your application accesses
|
||||
through reflection and other dynamic code patterns. Runtime Directives are used to control the
|
||||
.NET Native optimizer and ensure that it does not remove code accessed by your library. If your
|
||||
library does not do any reflection, then you generally do not need to edit this file. However,
|
||||
if your library reflects over types, especially types passed to it or derived from its types,
|
||||
then you should write Runtime Directives.
|
||||
|
||||
The most common use of reflection in libraries is to discover information about types passed
|
||||
to the library. Runtime Directives have three ways to express requirements on types passed to
|
||||
your library.
|
||||
|
||||
1. Parameter, GenericParameter, TypeParameter, TypeEnumerableParameter
|
||||
Use these directives to reflect over types passed as a parameter.
|
||||
|
||||
2. SubTypes
|
||||
Use a SubTypes directive to reflect over types derived from another type.
|
||||
|
||||
3. AttributeImplies
|
||||
Use an AttributeImplies directive to indicate that your library needs to reflect over
|
||||
types or methods decorated with an attribute.
|
||||
|
||||
For more information on writing Runtime Directives for libraries, please visit
|
||||
https://go.microsoft.com/fwlink/?LinkID=391919
|
||||
-->
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Library Name="GalaSoft.MvvmLight.Platform">
|
||||
|
||||
<!-- add directives for your library here -->
|
||||
|
||||
</Library>
|
||||
</Directives>
|
|
@ -0,0 +1,208 @@
|
|||
// ****************************************************************************
|
||||
// <copyright file="DialogService.cs" company="GalaSoft Laurent Bugnion">
|
||||
// Copyright © GalaSoft Laurent Bugnion 2009-2016
|
||||
// </copyright>
|
||||
// ****************************************************************************
|
||||
// <author>Laurent Bugnion</author>
|
||||
// <email>laurent@galasoft.ch</email>
|
||||
// <date>02.10.2014</date>
|
||||
// <project>GalaSoft.MvvmLight</project>
|
||||
// <web>http://www.mvvmlight.net</web>
|
||||
// <license>
|
||||
// See license.txt in this solution or http://www.galasoft.ch/license_MIT.txt
|
||||
// </license>
|
||||
// ****************************************************************************
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Popups;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// An implementation of <see cref="IDialogService"/> allowing
|
||||
/// to display simple dialogs to the user. Note that this class
|
||||
/// uses the built in Android dialogs which may or may not
|
||||
/// be sufficient for your needs. Using this class is easy
|
||||
/// but feel free to develop your own IDialogService implementation
|
||||
/// if needed.
|
||||
/// </summary>
|
||||
////[ClassInfo(typeof(IDialogService))]
|
||||
public class DialogService : IDialogService
|
||||
{
|
||||
/// <summary>
|
||||
/// Displays information about an error.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be shown to the user.</param>
|
||||
/// <param name="title">The title of the dialog box. This may be null.</param>
|
||||
/// <param name="buttonText">The text shown in the only button
|
||||
/// in the dialog box. If left null, the text "OK" will be used.</param>
|
||||
/// <param name="afterHideCallback">A callback that should be executed after
|
||||
/// the dialog box is closed by the user.</param>
|
||||
/// <returns>A Task allowing this async method to be awaited.</returns>
|
||||
public async Task ShowError(string message, string title, string buttonText, Action afterHideCallback)
|
||||
{
|
||||
var dialog = CreateDialog(message, title, buttonText, null, afterHideCallback);
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays information about an error.
|
||||
/// </summary>
|
||||
/// <param name="error">The exception of which the message must be shown to the user.</param>
|
||||
/// <param name="title">The title of the dialog box. This may be null.</param>
|
||||
/// <param name="buttonText">The text shown in the only button
|
||||
/// in the dialog box. If left null, the text "OK" will be used.</param>
|
||||
/// <param name="afterHideCallback">A callback that should be executed after
|
||||
/// the dialog box is closed by the user.</param>
|
||||
/// <returns>A Task allowing this async method to be awaited.</returns>
|
||||
public async Task ShowError(Exception error, string title, string buttonText, Action afterHideCallback)
|
||||
{
|
||||
var dialog = CreateDialog(error.Message, title, buttonText, null, afterHideCallback);
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays information to the user. The dialog box will have only
|
||||
/// one button with the text "OK".
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be shown to the user.</param>
|
||||
/// <param name="title">The title of the dialog box. This may be null.</param>
|
||||
/// <returns>A Task allowing this async method to be awaited.</returns>
|
||||
public async Task ShowMessage(string message, string title)
|
||||
{
|
||||
var dialog = CreateDialog(message, title);
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays information to the user. The dialog box will have only
|
||||
/// one button.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be shown to the user.</param>
|
||||
/// <param name="title">The title of the dialog box. This may be null.</param>
|
||||
/// <param name="buttonText">The text shown in the only button
|
||||
/// in the dialog box. If left null, the text "OK" will be used.</param>
|
||||
/// <param name="afterHideCallback">A callback that should be executed after
|
||||
/// the dialog box is closed by the user.</param>
|
||||
/// <returns>A Task allowing this async method to be awaited.</returns>
|
||||
public async Task ShowMessage(string message, string title, string buttonText, Action afterHideCallback)
|
||||
{
|
||||
var dialog = CreateDialog(message, title, buttonText, null, afterHideCallback);
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays information to the user. The dialog box will have only
|
||||
/// one button.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be shown to the user.</param>
|
||||
/// <param name="title">The title of the dialog box. This may be null.</param>
|
||||
/// <param name="buttonConfirmText">The text shown in the "confirm" button
|
||||
/// in the dialog box. If left null, the text "OK" will be used.</param>
|
||||
/// <param name="buttonCancelText">The text shown in the "cancel" button
|
||||
/// in the dialog box. If left null, the text "Cancel" will be used.</param>
|
||||
/// <param name="afterHideCallback">A callback that should be executed after
|
||||
/// the dialog box is closed by the user. The callback method will get a boolean
|
||||
/// parameter indicating if the "confirm" button (true) or the "cancel" button
|
||||
/// (false) was pressed by the user.</param>
|
||||
/// <returns>A Task allowing this async method to be awaited.</returns>
|
||||
public async Task<bool> ShowMessage(
|
||||
string message,
|
||||
string title,
|
||||
string buttonConfirmText,
|
||||
string buttonCancelText,
|
||||
Action<bool> afterHideCallback)
|
||||
{
|
||||
var result = false;
|
||||
|
||||
var dialog = CreateDialog(
|
||||
message,
|
||||
title,
|
||||
buttonConfirmText,
|
||||
buttonCancelText,
|
||||
null,
|
||||
afterHideCallback,
|
||||
r => result = r);
|
||||
|
||||
await dialog.ShowAsync();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays information to the user in a simple dialog box. The dialog box will have only
|
||||
/// one button with the text "OK". This method should be used for debugging purposes.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be shown to the user.</param>
|
||||
/// <param name="title">The title of the dialog box. This may be null.</param>
|
||||
/// <returns>A Task allowing this async method to be awaited.</returns>
|
||||
public async Task ShowMessageBox(string message, string title)
|
||||
{
|
||||
var dialog = CreateDialog(message, title);
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
private MessageDialog CreateDialog(
|
||||
string message,
|
||||
string title,
|
||||
string buttonConfirmText = "OK",
|
||||
string buttonCancelText = null,
|
||||
Action afterHideCallback = null,
|
||||
Action<bool> afterHideCallbackWithResponse = null,
|
||||
Action<bool> afterHideInternal = null)
|
||||
{
|
||||
var dialog = new MessageDialog(message, title);
|
||||
|
||||
dialog.Commands.Add(
|
||||
new UICommand(
|
||||
buttonConfirmText,
|
||||
o =>
|
||||
{
|
||||
if (afterHideCallback != null)
|
||||
{
|
||||
afterHideCallback();
|
||||
}
|
||||
|
||||
if (afterHideCallbackWithResponse != null)
|
||||
{
|
||||
afterHideCallbackWithResponse(true);
|
||||
}
|
||||
|
||||
if (afterHideInternal != null)
|
||||
{
|
||||
afterHideInternal(true);
|
||||
}
|
||||
}));
|
||||
|
||||
dialog.DefaultCommandIndex = 0;
|
||||
|
||||
if (!string.IsNullOrEmpty(buttonCancelText))
|
||||
{
|
||||
dialog.Commands.Add(
|
||||
new UICommand(
|
||||
buttonCancelText,
|
||||
o =>
|
||||
{
|
||||
if (afterHideCallback != null)
|
||||
{
|
||||
afterHideCallback();
|
||||
}
|
||||
|
||||
if (afterHideCallbackWithResponse != null)
|
||||
{
|
||||
afterHideCallbackWithResponse(false);
|
||||
}
|
||||
|
||||
if (afterHideInternal != null)
|
||||
{
|
||||
afterHideInternal(false);
|
||||
}
|
||||
}));
|
||||
|
||||
dialog.CancelCommandIndex = 1;
|
||||
}
|
||||
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
// ****************************************************************************
|
||||
// <copyright file="NavigationService.cs" company="GalaSoft Laurent Bugnion">
|
||||
// Copyright © GalaSoft Laurent Bugnion 2009-2016
|
||||
// </copyright>
|
||||
// ****************************************************************************
|
||||
// <author>Laurent Bugnion</author>
|
||||
// <email>laurent@galasoft.ch</email>
|
||||
// <date>02.10.2014</date>
|
||||
// <project>GalaSoft.MvvmLight</project>
|
||||
// <web>http://www.mvvmlight.net</web>
|
||||
// <license>
|
||||
// See license.txt in this solution or http://www.galasoft.ch/license_MIT.txt
|
||||
// </license>
|
||||
// ****************************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Windows 8 and Windows Phone Application 8.1 implementation of <see cref="INavigationService"/>.
|
||||
/// </summary>
|
||||
////[ClassInfo(typeof(INavigationService))]
|
||||
public class NavigationService : INavigationService
|
||||
{
|
||||
/// <summary>
|
||||
/// The key that is returned by the <see cref="CurrentPageKey"/> property
|
||||
/// when the current Page is the root page.
|
||||
/// </summary>
|
||||
public const string RootPageKey = "-- ROOT --";
|
||||
|
||||
/// <summary>
|
||||
/// The key that is returned by the <see cref="CurrentPageKey"/> property
|
||||
/// when the current Page is not found.
|
||||
/// This can be the case when the navigation wasn't managed by this NavigationService,
|
||||
/// for example when it is directly triggered in the code behind, and the
|
||||
/// NavigationService was not configured for this page type.
|
||||
/// </summary>
|
||||
public const string UnknownPageKey = "-- UNKNOWN --";
|
||||
|
||||
private readonly Dictionary<string, Type> _pagesByKey = new Dictionary<string, Type>();
|
||||
private Frame _currentFrame;
|
||||
|
||||
public Frame CurrentFrame
|
||||
{
|
||||
get
|
||||
{
|
||||
return _currentFrame ?? (_currentFrame = ((Frame)Window.Current.Content));
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_currentFrame = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanGoBack => CurrentFrame.CanGoBack;
|
||||
public bool CanGoForward => CurrentFrame.CanGoForward;
|
||||
|
||||
public void GoForward()
|
||||
{
|
||||
if (CurrentFrame.CanGoForward)
|
||||
{
|
||||
CurrentFrame.GoForward();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The key corresponding to the currently displayed page.
|
||||
/// </summary>
|
||||
public string CurrentPageKey
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_pagesByKey)
|
||||
{
|
||||
if (CurrentFrame.BackStackDepth == 0)
|
||||
{
|
||||
return RootPageKey;
|
||||
}
|
||||
|
||||
if (CurrentFrame.Content == null)
|
||||
{
|
||||
return UnknownPageKey;
|
||||
}
|
||||
|
||||
var currentType = CurrentFrame.Content.GetType();
|
||||
|
||||
if (_pagesByKey.All(p => p.Value != currentType))
|
||||
{
|
||||
return UnknownPageKey;
|
||||
}
|
||||
|
||||
var item = _pagesByKey.FirstOrDefault(
|
||||
i => i.Value == currentType);
|
||||
|
||||
return item.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If possible, discards the current page and displays the previous page
|
||||
/// on the navigation stack.
|
||||
/// </summary>
|
||||
public void GoBack()
|
||||
{
|
||||
if (CurrentFrame.CanGoBack)
|
||||
{
|
||||
CurrentFrame.GoBack();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays a new page corresponding to the given key.
|
||||
/// Make sure to call the <see cref="Configure"/>
|
||||
/// method first.
|
||||
/// </summary>
|
||||
/// <param name="pageKey">The key corresponding to the page
|
||||
/// that should be displayed.</param>
|
||||
/// <exception cref="ArgumentException">When this method is called for
|
||||
/// a key that has not been configured earlier.</exception>
|
||||
public void NavigateTo(string pageKey)
|
||||
{
|
||||
NavigateTo(pageKey, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays a new page corresponding to the given key,
|
||||
/// and passes a parameter to the new page.
|
||||
/// Make sure to call the <see cref="Configure"/>
|
||||
/// method first.
|
||||
/// </summary>
|
||||
/// <param name="pageKey">The key corresponding to the page
|
||||
/// that should be displayed.</param>
|
||||
/// <param name="parameter">The parameter that should be passed
|
||||
/// to the new page.</param>
|
||||
/// <exception cref="ArgumentException">When this method is called for
|
||||
/// a key that has not been configured earlier.</exception>
|
||||
public virtual void NavigateTo(string pageKey, object parameter)
|
||||
{
|
||||
lock (_pagesByKey)
|
||||
{
|
||||
if (!_pagesByKey.ContainsKey(pageKey))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
string.Format(
|
||||
"No such page: {0}. Did you forget to call NavigationService.Configure?",
|
||||
pageKey),
|
||||
"pageKey");
|
||||
}
|
||||
|
||||
CurrentFrame.Navigate(_pagesByKey[pageKey], parameter);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a key/page pair to the navigation service.
|
||||
/// </summary>
|
||||
/// <param name="key">The key that will be used later
|
||||
/// in the <see cref="NavigateTo(string)"/> or <see cref="NavigateTo(string, object)"/> methods.</param>
|
||||
/// <param name="pageType">The type of the page corresponding to the key.</param>
|
||||
public void Configure(string key, Type pageType)
|
||||
{
|
||||
lock (_pagesByKey)
|
||||
{
|
||||
if (_pagesByKey.ContainsKey(key))
|
||||
{
|
||||
throw new ArgumentException("This key is already used: " + key);
|
||||
}
|
||||
|
||||
if (_pagesByKey.Any(p => p.Value == pageType))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"This type is already configured with key " + _pagesByKey.First(p => p.Value == pageType).Key);
|
||||
}
|
||||
|
||||
_pagesByKey.Add(
|
||||
key,
|
||||
pageType);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetKeyForPage(Type page)
|
||||
{
|
||||
lock (_pagesByKey)
|
||||
{
|
||||
if (_pagesByKey.ContainsValue(page))
|
||||
{
|
||||
return _pagesByKey.FirstOrDefault(p => p.Value == page).Key;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"The page '{page.Name}' is unknown by the NavigationService");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче