SavePage uses nav service

This commit is contained in:
Geoffroy BONNEVILLE
2020-04-21 13:14:56 +02:00
parent a1085b6010
commit c81f8bc835
4 changed files with 10 additions and 22 deletions

View File

@@ -160,7 +160,6 @@ namespace ModernKeePass
var launchActivatedEventArgs = e as LaunchActivatedEventArgs;
if (launchActivatedEventArgs != null && rootFrame.Content == null)
//rootFrame.Navigate(typeof(MainPage), launchActivatedEventArgs.Arguments);
_navigation.NavigateTo(Constants.Navigation.MainPage, launchActivatedEventArgs.Arguments);
// Ensure the current window is active
@@ -251,12 +250,10 @@ namespace ModernKeePass
Name = file.DisplayName,
Path = file.Path
};
//rootFrame.Navigate(typeof(MainPage), fileInfo);
_navigation.NavigateTo(Constants.Navigation.MainPage, fileInfo);
}
else
{
//rootFrame.Navigate(typeof(MainPage));
_navigation.NavigateTo(Constants.Navigation.MainPage);
}

View File

@@ -1,14 +1,14 @@
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Database.Commands.CloseDatabase;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Views;
using ModernKeePass.Common;
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
namespace ModernKeePass.ViewModels
{
@@ -18,15 +18,16 @@ namespace ModernKeePass.ViewModels
public RelayCommand SaveCommand { get; }
public RelayCommand CloseCommand { get; }
public Frame Frame { get; set; }
private readonly IMediator _mediator;
private readonly INavigationService _navigation;
public SaveVm() : this(App.Services.GetRequiredService<IMediator>()) { }
public SaveVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<INavigationService>()) { }
public SaveVm(IMediator mediator)
public SaveVm(IMediator mediator, INavigationService navigation)
{
_mediator = mediator;
_navigation = navigation;
SaveCommand = new RelayCommand(async () => await Save(), () => IsSaveEnabled);
CloseCommand = new RelayCommand(async () => await Close());
}
@@ -35,20 +36,20 @@ namespace ModernKeePass.ViewModels
{
await _mediator.Send(new SaveDatabaseCommand());
if (close) await _mediator.Send(new CloseDatabaseCommand());
Frame.Navigate(typeof(MainPage));
_navigation.NavigateTo(Constants.Navigation.MainPage);
}
public async Task Save(StorageFile file)
{
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
await _mediator.Send(new SaveDatabaseCommand { FilePath = token });
Frame.Navigate(typeof(MainPage));
_navigation.NavigateTo(Constants.Navigation.MainPage);
}
public async Task Close()
{
await _mediator.Send(new CloseDatabaseCommand());
Frame.Navigate(typeof(MainPage));
_navigation.NavigateTo(Constants.Navigation.MainPage);
}
}
}

View File

@@ -4,8 +4,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="using:ModernKeePass.ViewModels"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
x:Class="ModernKeePass.Views.SaveDatabasePage"
mc:Ignorable="d">
<Page.DataContext>

View File

@@ -2,8 +2,6 @@
using System.Collections.Generic;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using ModernKeePass.ViewModels;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
@@ -21,12 +19,6 @@ namespace ModernKeePass.Views
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Model.Frame = e.Parameter as Frame;
}
private async void SaveAsButton_OnClick(object sender, RoutedEventArgs e)
{
var savePicker = new FileSavePicker