WIP ViewModelLocator - Messenger and Recent issues

Refactoring
Code cleanup
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-23 19:00:38 +02:00
parent 2b8f9bd5f0
commit d211453553
59 changed files with 309 additions and 934 deletions

View File

@@ -1,21 +1,26 @@
<Application x:Class="ModernKeePass.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RequestedTheme="Light" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionaries/TextBoxWithButtonStyle.xaml">
<Application x:Class="ModernKeePass.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedTheme="Light"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d1p1:Ignorable="d"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionaries/TextBoxWithButtonStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/HamburgerButtonStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/ListViewLeftIndicatorStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/NoBorderButtonStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/NoBorderToggleButtonStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/Styles.xaml">
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="using:ModernKeePass.ViewModels" />
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/HamburgerButtonStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/ListViewLeftIndicatorStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/NoBorderButtonStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/NoBorderToggleButtonStyle.xaml">
</ResourceDictionary>
<ResourceDictionary Source="ResourceDictionaries/Styles.xaml">
<!--<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="using:ModernKeePass.ViewModel" />-->
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application.Resources>
</Application>

View File

@@ -88,10 +88,9 @@ namespace ModernKeePass
if (realException is SaveException)
{
var innerException = realException.InnerException;
unhandledExceptionEventArgs.Handled = true;
_hockey.TrackException(innerException);
await _dialog.ShowMessage(innerException?.Message,
_hockey.TrackException(realException);
await _dialog.ShowMessage(realException.Message,
_resource.GetResourceValue("MessageDialogSaveErrorTitle"),
_resource.GetResourceValue("MessageDialogSaveErrorButtonSaveAs"),
_resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"),
@@ -112,7 +111,7 @@ namespace ModernKeePass
var file = await savePicker.PickSaveFileAsync().AsTask();
if (file != null)
{
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
await _mediator.Send(new SaveDatabaseCommand {FilePath = token});
}
}
@@ -252,7 +251,7 @@ namespace ModernKeePass
if (file != null)
{
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
var fileInfo = new FileInfo
{
Id = token,

View File

@@ -25,7 +25,6 @@ namespace ModernKeePass
nav.Configure(Constants.Navigation.GroupPage, typeof(GroupDetailPage));
return nav;
});
services.AddSingleton(provider => Messenger.Default);
services.AddTransient(typeof(IDialogService), typeof(DialogService));
services.AddSingleton(provider =>

View File

@@ -1,11 +0,0 @@
using System.Threading.Tasks;
using Windows.Storage;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Interfaces
{
public interface IImportService<in T> where T: IFormat
{
Task Import(T format, IStorageFile source, GroupVm group);
}
}

View File

@@ -1,22 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Application.Group.Models;
namespace ModernKeePass.Interfaces
{
public interface IVmEntity
{
Symbol Icon { get; }
string Id { get; }
string Title { get; set; }
IEnumerable<GroupVm> BreadCrumb { get; }
bool IsEditMode { get; }
/// <summary>
/// Move a entity to the destination group
/// </summary>
/// <param name="destination">The destination to move the entity to</param>
Task Move(GroupVm destination);
}
}

View File

@@ -1,34 +0,0 @@
using GalaSoft.MvvmLight;
namespace ModernKeePass.ViewModel
{
/// <summary>
/// This class contains properties that the main View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class MainViewModel : ViewModelBase
{
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel()
{
////if (IsInDesignMode)
////{
//// // Code runs in Blend --> create design time data.
////}
////else
////{
//// // Code runs "for real"
////}
}
}
}

View File

@@ -1,55 +0,0 @@
/*
In App.xaml:
<Application.Resources>
<vm:ViewModelLocator xmlns:vm="clr-namespace:ModernKeePass"
x:Key="Locator" />
</Application.Resources>
In the View:
DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
You can also use Blend to do all this with the tool's support.
See http://www.galasoft.ch/mvvm
*/
using CommonServiceLocator;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
namespace ModernKeePass.ViewModel
{
/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// </summary>
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
////if (ViewModelBase.IsInDesignModeStatic)
////{
//// // Create design time view services and models
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
////}
////else
////{
//// // Create run time view services and models
//// SimpleIoc.Default.Register<IDataService, DataService>();
////}
SimpleIoc.Default.Register<MainViewModel>();
}
public MainViewModel Main => ServiceLocator.Current.GetInstance<MainViewModel>();
public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
}

View File

@@ -1,191 +0,0 @@
using System;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Commands.CreateDatabase;
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Database.Queries.OpenDatabase;
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels
{
public class CompositeKeyVm: ObservableObject
{
public enum StatusTypes
{
Normal = 0,
Error = 1,
Warning = 3,
Success = 5
}
public bool HasPassword
{
get { return _hasPassword; }
set
{
Set(() => HasPassword, ref _hasPassword, value);
RaisePropertyChanged(nameof(IsValid));
}
}
public bool HasKeyFile
{
get { return _hasKeyFile; }
set
{
Set(() => HasKeyFile, ref _hasKeyFile, value);
RaisePropertyChanged(nameof(IsValid));
}
}
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFilePath != null);
public string Status
{
get { return _status; }
set { Set(() => Status, ref _status, value); }
}
public int StatusType
{
get { return _statusType; }
set { Set(() => StatusType, ref _statusType, value); }
}
public string Password
{
get { return _password; }
set
{
_password = value;
RaisePropertyChanged(nameof(PasswordComplexityIndicator));
StatusType = (int)StatusTypes.Normal;
Status = string.Empty;
}
}
public string KeyFilePath
{
get { return _keyFilePath; }
set
{
_keyFilePath = value;
RaisePropertyChanged(nameof(IsValid));
}
}
public string KeyFileText
{
get { return _keyFileText; }
set { Set(() => KeyFileText, ref _keyFileText, value); }
}
public string RootGroupId { get; set; }
public double PasswordComplexityIndicator => _mediator.Send(new EstimatePasswordComplexityQuery { Password = Password }).GetAwaiter().GetResult();
private bool _hasPassword;
private bool _hasKeyFile;
private bool _isOpening;
private string _password = string.Empty;
private string _status;
private int _statusType;
private string _keyFilePath;
private string _keyFileText;
private readonly IMediator _mediator;
private readonly ISettingsProxy _settings;
private readonly IResourceProxy _resource;
public CompositeKeyVm() : this(
App.Services.GetRequiredService<IMediator>(),
App.Services.GetRequiredService<ISettingsProxy>(),
App.Services.GetRequiredService<IResourceProxy>()) { }
public CompositeKeyVm(IMediator mediator, ISettingsProxy settings, IResourceProxy resource)
{
_mediator = mediator;
_settings = settings;
_resource = resource;
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
}
public async Task<bool> OpenDatabase(string databaseFilePath, bool createNew)
{
try
{
_isOpening = true;
RaisePropertyChanged(nameof(IsValid));
if (createNew)
{
await _mediator.Send(new CreateDatabaseCommand
{
FilePath = databaseFilePath,
KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null,
Name = "New Database",
CreateSampleData = _settings.GetSetting<bool>("Sample")
});
}
else
{
await _mediator.Send(new OpenDatabaseQuery {
FilePath = databaseFilePath,
KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null,
});
}
RootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
return true;
}
catch (ArgumentException)
{
var errorMessage = new StringBuilder($"{_resource.GetResourceValue("CompositeKeyErrorOpen")}\n");
if (HasPassword) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserPassword"));
if (HasKeyFile) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserKeyFile"));
UpdateStatus(errorMessage.ToString(), StatusTypes.Error);
}
catch (Exception e)
{
var error = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}";
UpdateStatus(error, StatusTypes.Error);
}
finally
{
_isOpening = false;
RaisePropertyChanged(nameof(IsValid));
}
return false;
}
public async Task UpdateKey()
{
await _mediator.Send(new UpdateCredentialsCommand
{
KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null,
});
UpdateStatus(_resource.GetResourceValue("CompositeKeyUpdated"), StatusTypes.Success);
}
public async Task CreateKeyFile(FileInfo file)
{
// TODO: implement entropy generator
await _mediator.Send(new GenerateKeyFileCommand {KeyFilePath = file.Id});
KeyFilePath = file.Path;
KeyFileText = file.Name;
}
private void UpdateStatus(string text, StatusTypes type)
{
Status = text;
StatusType = (int)type;
}
}
}

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
@@ -26,14 +27,12 @@ using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Application.Security.Commands.GeneratePassword;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Interfaces;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Extensions;
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
namespace ModernKeePass.ViewModels
{
public class EntryDetailVm : ObservableObject, IVmEntity
public class EntryDetailVm : ObservableObject
{
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
@@ -230,6 +229,7 @@ namespace ModernKeePass.ViewModels
private readonly INavigationService _navigation;
private readonly IResourceProxy _resource;
private readonly IDialogService _dialog;
private readonly INotificationService _notification;
private readonly GroupVm _parent;
private EntryVm _selectedItem;
private int _selectedIndex;
@@ -244,14 +244,16 @@ namespace ModernKeePass.ViewModels
App.Services.GetRequiredService<IMediator>(),
App.Services.GetRequiredService<INavigationService>(),
App.Services.GetRequiredService<IResourceProxy>(),
App.Services.GetRequiredService<IDialogService>()) { }
App.Services.GetRequiredService<IDialogService>(),
App.Services.GetRequiredService<INotificationService>()) { }
public EntryDetailVm(string entryId, IMediator mediator, INavigationService navigation, IResourceProxy resource, IDialogService dialog)
public EntryDetailVm(string entryId, IMediator mediator, INavigationService navigation, IResourceProxy resource, IDialogService dialog, INotificationService notification)
{
_mediator = mediator;
_navigation = navigation;
_resource = resource;
_dialog = dialog;
_notification = notification;
SelectedItem = _mediator.Send(new GetEntryQuery { Id = entryId }).GetAwaiter().GetResult();
_parent = _mediator.Send(new GetGroupQuery { Id = SelectedItem.ParentGroupId }).GetAwaiter().GetResult();
History = new ObservableCollection<EntryVm> { SelectedItem };
@@ -273,31 +275,22 @@ namespace ModernKeePass.ViewModels
{
if (IsCurrentEntry)
{
var isRecycleOnDelete = IsRecycleOnDelete;
var message = isRecycleOnDelete
? _resource.GetResourceValue("EntryRecyclingConfirmation")
: _resource.GetResourceValue("EntryDeletingConfirmation");
await _dialog.ShowMessage(message,
_resource.GetResourceValue("EntityDeleteTitle"),
_resource.GetResourceValue("EntityDeleteActionButton"),
_resource.GetResourceValue("EntityDeleteCancelButton"),
async isOk =>
{
if (isOk)
if (IsRecycleOnDelete)
{
await Delete();
_notification.Show(_resource.GetResourceValue("EntryRecyclingConfirmation"), _resource.GetResourceValue("EntryRecycled"));
}
else
{
await _dialog.ShowMessage(_resource.GetResourceValue("EntryDeletingConfirmation"),
_resource.GetResourceValue("EntityDeleteTitle"),
_resource.GetResourceValue("EntityDeleteActionButton"),
_resource.GetResourceValue("EntityDeleteCancelButton"),
async isOk =>
{
var text = isRecycleOnDelete
? _resource.GetResourceValue("EntryRecycled")
: _resource.GetResourceValue("EntryDeleted");
//ToastNotificationHelper.ShowMovedToast(Entity, _resource.GetResourceValue("EntityDeleting"), text);
await _mediator.Send(new DeleteEntryCommand
{
EntryId = Id, ParentGroupId = SelectedItem.ParentGroupId,
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
});
_navigation.GoBack();
}
});
if (isOk) await Delete();
});
}
}
else
{
@@ -305,14 +298,11 @@ namespace ModernKeePass.ViewModels
_resource.GetResourceValue("EntityDeleteActionButton"),
_resource.GetResourceValue("EntityDeleteCancelButton"), async isOk =>
{
if (isOk)
{
//ToastNotificationHelper.ShowMovedToast(Entity, _resource.GetResourceValue("EntityDeleting"), text);
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
History.RemoveAt(SelectedIndex);
SelectedIndex = 0;
SaveCommand.RaiseCanExecuteChanged();
}
if (!isOk) return;
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
History.RemoveAt(SelectedIndex);
SelectedIndex = 0;
SaveCommand.RaiseCanExecuteChanged();
});
}
}
@@ -368,5 +358,16 @@ namespace ModernKeePass.ViewModels
SaveCommand.RaiseCanExecuteChanged();
_isDirty = false;
}
private async Task Delete()
{
await _mediator.Send(new DeleteEntryCommand
{
EntryId = Id,
ParentGroupId = SelectedItem.ParentGroupId,
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
});
_navigation.GoBack();
}
}
}

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
@@ -29,13 +30,11 @@ using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Application.Group.Queries.SearchEntries;
using ModernKeePass.Common;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Interfaces;
using ModernKeePass.Models;
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
namespace ModernKeePass.ViewModels
{
public class GroupDetailVm : ObservableObject, IVmEntity
public class GroupDetailVm : ObservableObject
{
public ObservableCollection<EntryVm> Entries { get; }
@@ -102,6 +101,7 @@ namespace ModernKeePass.ViewModels
private readonly IResourceProxy _resource;
private readonly INavigationService _navigation;
private readonly IDialogService _dialog;
private readonly INotificationService _notification;
private readonly GroupVm _group;
private readonly GroupVm _parent;
private bool _isEditMode;
@@ -113,15 +113,17 @@ namespace ModernKeePass.ViewModels
App.Services.GetRequiredService<IMediator>(),
App.Services.GetRequiredService<IResourceProxy>(),
App.Services.GetRequiredService<INavigationService>(),
App.Services.GetRequiredService<IDialogService>())
App.Services.GetRequiredService<IDialogService>(),
App.Services.GetRequiredService<INotificationService>())
{ }
public GroupDetailVm(string groupId, IMediator mediator, IResourceProxy resource, INavigationService navigation, IDialogService dialog)
public GroupDetailVm(string groupId, IMediator mediator, IResourceProxy resource, INavigationService navigation, IDialogService dialog, INotificationService notification)
{
_mediator = mediator;
_resource = resource;
_navigation = navigation;
_dialog = dialog;
_notification = notification;
_group = _mediator.Send(new GetGroupQuery { Id = groupId }).GetAwaiter().GetResult();
if (!string.IsNullOrEmpty(_group.ParentGroupId))
{
@@ -145,29 +147,21 @@ namespace ModernKeePass.ViewModels
private async Task AskForDelete()
{
var message = IsRecycleOnDelete
? _resource.GetResourceValue("GroupRecyclingConfirmation")
: _resource.GetResourceValue("GroupDeletingConfirmation");
await _dialog.ShowMessage(message, _resource.GetResourceValue("EntityDeleteTitle"),
if (IsRecycleOnDelete)
{
await Delete();
_notification.Show(_resource.GetResourceValue("GroupRecyclingConfirmation"), _resource.GetResourceValue("GroupRecycled"));
}
else
{
await _dialog.ShowMessage(_resource.GetResourceValue("GroupDeletingConfirmation"), _resource.GetResourceValue("EntityDeleteTitle"),
_resource.GetResourceValue("EntityDeleteActionButton"),
_resource.GetResourceValue("EntityDeleteCancelButton"),
async isOk =>
{
if (isOk)
{
var text = IsRecycleOnDelete
? _resource.GetResourceValue("GroupRecycled")
: _resource.GetResourceValue("GroupDeleted");
//ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
await _mediator.Send(new DeleteGroupCommand
{
GroupId = _group.Id, ParentGroupId = _group.ParentGroupId,
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
});
_navigation.GoBack();
}
if (isOk) await Delete();
});
}
}
@@ -244,5 +238,16 @@ namespace ModernKeePass.ViewModels
RaisePropertyChanged(nameof(Groups));
SaveCommand.RaiseCanExecuteChanged();
}
private async Task Delete()
{
await _mediator.Send(new DeleteGroupCommand
{
GroupId = _group.Id,
ParentGroupId = _group.ParentGroupId,
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
});
_navigation.GoBack();
}
}
}

View File

@@ -4,6 +4,7 @@ using Windows.ApplicationModel;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight;
using MediatR;
using Messages;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Queries.GetDatabase;
@@ -12,11 +13,23 @@ using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Models;
using ModernKeePass.ViewModels.ListItems;
using ModernKeePass.Views;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.Views;
using ModernKeePass.Application.Database.Commands.CloseDatabase;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Common;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.ViewModels
{
public class MainVm : ObservableObject, IHasSelectableObject
public class MainVm : ViewModelBase, IHasSelectableObject
{
private readonly IMediator _mediator;
private readonly IRecentProxy _recent;
private readonly IResourceProxy _resource;
private readonly IDialogService _dialog;
private readonly INotificationService _notification;
private readonly INavigationService _navigation;
private IOrderedEnumerable<IGrouping<string, MainMenuItemVm>> _mainMenuItems;
private ISelectableModel _selectedItem;
@@ -55,19 +68,45 @@ namespace ModernKeePass.ViewModels
destinationFrame,
App.Services.GetRequiredService<IMediator>(),
App.Services.GetRequiredService<IRecentProxy>(),
App.Services.GetRequiredService<IResourceProxy>(),
App.Services.GetRequiredService<IResourceProxy>(),
App.Services.GetRequiredService<IDialogService>(),
App.Services.GetRequiredService<INotificationService>(),
App.Services.GetRequiredService<INavigationService>(),
databaseFile)
{ }
public MainVm(Frame referenceFrame, Frame destinationFrame, IMediator mediator, IRecentProxy recent, IResourceProxy resource, FileInfo databaseFile = null)
public MainVm(
Frame referenceFrame,
Frame destinationFrame,
IMediator mediator,
IRecentProxy recent,
IResourceProxy resource,
IDialogService dialog,
INotificationService notification,
INavigationService navigation,
FileInfo databaseFile = null)
{
var database = mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
_mediator = mediator;
_recent = recent;
_resource = resource;
_dialog = dialog;
_notification = notification;
_navigation = navigation;
BuildMainMenuItems(referenceFrame, destinationFrame, databaseFile);
MessengerInstance.Register<DatabaseOpenedMessage>(this, NavigateToPage);
MessengerInstance.Register<DatabaseAlreadyOpenedMessage>(this, async message => await DisplaySaveConfirmation(message));
}
private void BuildMainMenuItems(Frame referenceFrame, Frame destinationFrame, FileInfo databaseFile)
{
var database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
{
new MainMenuItemVm
{
Title = resource.GetResourceValue("MainMenuItemOpen"),
Title = _resource.GetResourceValue("MainMenuItemOpen"),
PageType = typeof(OpenDatabasePage),
Destination = destinationFrame,
Parameter = databaseFile,
@@ -76,14 +115,14 @@ namespace ModernKeePass.ViewModels
},
new MainMenuItemVm
{
Title = resource.GetResourceValue("MainMenuItemNew"),
Title = _resource.GetResourceValue("MainMenuItemNew"),
PageType = typeof(NewDatabasePage),
Destination = destinationFrame,
SymbolIcon = Symbol.Add
},
new MainMenuItemVm
{
Title = resource.GetResourceValue("MainMenuItemSave"),
Title = _resource.GetResourceValue("MainMenuItemSave"),
PageType = typeof(SaveDatabasePage),
Destination = destinationFrame,
Parameter = referenceFrame,
@@ -93,31 +132,31 @@ namespace ModernKeePass.ViewModels
},
new MainMenuItemVm
{
Title = resource.GetResourceValue("MainMenuItemRecent"),
Title = _resource.GetResourceValue("MainMenuItemRecent"),
PageType = typeof(RecentDatabasesPage),
Destination = destinationFrame,
Parameter = referenceFrame,
SymbolIcon = Symbol.Copy,
IsSelected = !database.IsOpen && recent.EntryCount > 0,
IsEnabled = recent.EntryCount > 0
IsSelected = !database.IsOpen && _recent.EntryCount > 0,
IsEnabled = _recent.EntryCount > 0
},
new MainMenuItemVm
{
Title = resource.GetResourceValue("MainMenuItemSettings"),
Title = _resource.GetResourceValue("MainMenuItemSettings"),
PageType = typeof(SettingsPage),
Destination = referenceFrame,
SymbolIcon = Symbol.Setting
},
new MainMenuItemVm
{
Title = resource.GetResourceValue("MainMenuItemAbout"),
Title = _resource.GetResourceValue("MainMenuItemAbout"),
PageType = typeof(AboutPage),
Destination = destinationFrame,
SymbolIcon = Symbol.Help
},
new MainMenuItemVm
{
Title = resource.GetResourceValue("MainMenuItemDonate"),
Title = _resource.GetResourceValue("MainMenuItemDonate"),
PageType = typeof(DonatePage),
Destination = destinationFrame,
SymbolIcon = Symbol.Shop
@@ -137,8 +176,41 @@ namespace ModernKeePass.ViewModels
Group = "Databases",
SymbolIcon = Symbol.ProtectedDocument
});
MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
}
private void NavigateToPage(DatabaseOpenedMessage message)
{
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
}
private async Task DisplaySaveConfirmation(DatabaseAlreadyOpenedMessage message)
{
var database = await _mediator.Send(new GetDatabaseQuery());
await _dialog.ShowMessage(string.Format(_resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
_resource.GetResourceValue("MessageDialogDBOpenTitle"),
_resource.GetResourceValue("MessageDialogDBOpenButtonSave"),
_resource.GetResourceValue("MessageDialogDBOpenButtonDiscard"),
async isOk =>
{
if (isOk)
{
try
{
await _mediator.Send(new SaveDatabaseCommand());
_notification.Show(database.Name, _resource.GetResourceValue("ToastSavedMessage"));
}
catch (SaveException exception)
{
_notification.Show(exception.Source, exception.Message);
return;
}
}
await _mediator.Send(new CloseDatabaseCommand());
MessengerInstance.Send(new DatabaseClosedMessage { Parameter = message.Parameter });
});
}
}
}

View File

@@ -43,9 +43,7 @@ namespace ModernKeePass.ViewModels
}
}
}
public SettingsVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<IResourceProxy>()) { }
public SettingsVm(IMediator mediator, IResourceProxy resource)
{
var database = mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();

View File

@@ -3,6 +3,7 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Navigation;
using GalaSoft.MvvmLight.Command;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;

View File

@@ -22,15 +22,6 @@ namespace ModernKeePass.Views
#region Inscription de NavigationHelper
/// Les méthodes fournies dans cette section sont utilisées simplement pour permettre
/// NavigationHelper pour répondre aux méthodes de navigation de la page.
///
/// La logique spécifique à la page doit être placée dans les gestionnaires d'événements pour
/// <see cref="Common.NavigationHelper.LoadState"/>
/// et <see cref="Common.NavigationHelper.SaveState"/>.
/// Le paramètre de navigation est disponible dans la méthode LoadState
/// en plus de l'état de page conservé durant une session antérieure.
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var args = e.Parameter as NavigationItem;

View File

@@ -37,16 +37,7 @@ namespace ModernKeePass.Views
}
#region NavigationHelper registration
/// The methods provided in this section are simply used to allow
/// NavigationHelper to respond to the page's navigation methods.
///
/// Page specific logic should be placed in event handlers for the
/// <see cref="Common.NavigationHelper.LoadState"/>
/// and <see cref="Common.NavigationHelper.SaveState"/>.
/// The navigation parameter is available in the LoadState method
/// in addition to page state preserved during an earlier session.
///
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var navigationItem = e.Parameter as NavigationItem;

View File

@@ -18,10 +18,16 @@ namespace ModernKeePass.Views
public MainPage()
{
InitializeComponent();
Unloaded += MainPage_Unloaded;
ListView = MenuListView;
ListViewSource = MenuItemsSource;
}
private void MainPage_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Model.Cleanup();
}
private new void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
base.ListView_SelectionChanged(sender, e);

View File

@@ -5,15 +5,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:ModernKeePass.Converters"
xmlns:viewModels="using:ModernKeePass.ViewModels"
xmlns:userControls="using:ModernKeePass.Views.UserControls"
mc:Ignorable="d">
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=New}">
<Page.Resources>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<viewModels:NewVm x:Key="ViewModel"/>
</Page.Resources>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<HyperlinkButton x:Uid="NewCreateButton" Click="CreateDatabaseButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" />
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">

View File

@@ -20,7 +20,7 @@ namespace ModernKeePass.Views
public sealed partial class NewDatabasePage
{
private readonly IResourceProxy _resource;
private NewVm Model => (NewVm)Resources["ViewModel"];
private NewVm Model => (NewVm)DataContext;
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
public NewDatabasePage(IResourceProxy resource)
@@ -41,7 +41,7 @@ namespace ModernKeePass.Views
var file = await savePicker.PickSaveFileAsync().AsTask();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
var fileInfo = new FileInfo
{
Id = token,

View File

@@ -3,17 +3,16 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="using:ModernKeePass.ViewModels"
xmlns:converters="using:ModernKeePass.Converters"
xmlns:userControls="using:ModernKeePass.Views.UserControls"
x:Class="ModernKeePass.Views.OpenDatabasePage"
mc:Ignorable="d">
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=Open}">
<Page.Resources>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<viewModels:OpenVm x:Key="ViewModel"/>
</Page.Resources>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<HyperlinkButton x:Uid="OpenBrowseButton" Click="ButtonBase_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenBrowseDesc" />
<!--<HyperlinkButton x:Uid="OpenUrlButton" IsEnabled="False" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />

View File

@@ -3,13 +3,7 @@ using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Navigation;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Views;
using Messages;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Common;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Models;
using ModernKeePass.ViewModels;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
@@ -21,24 +15,11 @@ namespace ModernKeePass.Views
/// </summary>
public sealed partial class OpenDatabasePage
{
private readonly INavigationService _navigation;
private OpenVm Model => (OpenVm)Resources["ViewModel"];
public OpenDatabasePage(): this(
App.Services.GetRequiredService<INavigationService>(),
App.Services.GetRequiredService<IMessenger>()) { }
public OpenDatabasePage(INavigationService navigation, IMessenger messenger)
private OpenVm Model => (OpenVm)DataContext;
public OpenDatabasePage()
{
_navigation = navigation;
InitializeComponent();
messenger.Register<DatabaseOpenedMessage>(this, NavigateToPage);
}
private void NavigateToPage(DatabaseOpenedMessage message)
{
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
@@ -64,8 +45,7 @@ namespace ModernKeePass.Views
var file = await picker.PickSingleFileAsync().AsTask();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
var fileInfo = new FileInfo
{
Path = file.Path,

View File

@@ -3,16 +3,15 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="using:ModernKeePass.ViewModels"
xmlns:converters="using:ModernKeePass.Converters"
xmlns:userControls="using:ModernKeePass.Views.UserControls"
x:Class="ModernKeePass.Views.RecentDatabasesPage"
mc:Ignorable="d">
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=Recent}">
<Page.Resources>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<viewModels:RecentVm x:Key="ViewModel"/>
</Page.Resources>
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />

View File

@@ -1,11 +1,5 @@
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Views;
using Messages;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Common;
using ModernKeePass.Models;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Views
@@ -15,29 +9,11 @@ namespace ModernKeePass.Views
/// </summary>
public sealed partial class RecentDatabasesPage
{
private RecentVm Model => (RecentVm)Resources["ViewModel"];
private readonly INavigationService _navigation;
private readonly IMessenger _messenger;
public RecentDatabasesPage(): this(
App.Services.GetRequiredService<INavigationService>(),
App.Services.GetRequiredService<IMessenger>())
{ }
public RecentDatabasesPage(INavigationService navigation, IMessenger messenger)
{
_navigation = navigation;
_messenger = messenger;
InitializeComponent();
messenger.Register<DatabaseOpeningMessage>(this, action => Model.UpdateAccessTime(action.Token));
messenger.Register<DatabaseOpenedMessage>(this, NavigateToPage);
}
private RecentVm Model => (RecentVm)DataContext;
private void NavigateToPage(DatabaseOpenedMessage message)
public RecentDatabasesPage()
{
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
InitializeComponent();
}
}
}

View File

@@ -3,12 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="using:ModernKeePass.ViewModels"
x:Class="ModernKeePass.Views.SaveDatabasePage"
mc:Ignorable="d">
<Page.DataContext>
<viewModels:SaveVm/>
</Page.DataContext>
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=Save}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<HyperlinkButton x:Uid="SaveButton" Command="{Binding SaveCommand}" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />

View File

@@ -4,17 +4,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:ModernKeePass.Controls"
xmlns:viewModels="using:ModernKeePass.ViewModels"
xmlns:basePages="using:ModernKeePass.Views.BasePages"
x:Name="PageRoot"
x:Class="ModernKeePass.Views.SettingsPage"
mc:Ignorable="d">
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=Settings}">
<Page.Resources>
<CollectionViewSource x:Name="MenuItemsSource" Source="{Binding MenuItems}" IsSourceGrouped="True" />
</Page.Resources>
<Page.DataContext>
<viewModels:SettingsVm />
</Page.DataContext>
<Page.Background>
<StaticResource ResourceKey="ApplicationPageBackgroundThemeBrush"/>

View File

@@ -5,12 +5,11 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:ModernKeePass.Converters"
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
mc:Ignorable="d">
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsDatabase}">
<Page.Resources>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
<listItems:SettingsDatabaseVm x:Key="ViewModel"/>
</Page.Resources>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">

View File

@@ -4,13 +4,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
mc:Ignorable="d">
<Page.Resources>
<listItems:SettingsNewVm x:Key="ViewModel"/>
</Page.Resources>
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsNew}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel.Resources>
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding FileFormats}" />
</StackPanel.Resources>

View File

@@ -4,13 +4,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
mc:Ignorable="d">
<Page.Resources>
<listItems:SettingsSaveVm x:Name="ViewModel"/>
</Page.Resources>
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsSave}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Uid="SettingsSaveDatabaseSuspendTitle" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,10"/>
<TextBlock x:Uid="SettingsSaveDatabaseSuspendDesc" TextWrapping="WrapWholeWords" Margin="5,0,0,10"/>
<ToggleSwitch x:Uid="SettingsSaveDatabaseSuspend" IsOn="{Binding IsSaveSuspend, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" />

View File

@@ -5,13 +5,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:userControls="using:ModernKeePass.Views.UserControls"
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
mc:Ignorable="d">
<Page.Resources>
<listItems:SettingsSecurityVm x:Key="ViewModel"/>
</Page.Resources>
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsSecurity}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Uid="SettingsSecurityTitle" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,0" />
<TextBlock TextWrapping="WrapWholeWords" Margin="5,0,0,0">
<Run x:Uid="SettingsSecurityDesc1" />

View File

@@ -7,14 +7,12 @@
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:converters="using:ModernKeePass.Converters"
xmlns:viewModels="using:ModernKeePass.ViewModels"
mc:Ignorable="d" >
<UserControl.Resources>
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
<viewModels:OpenDatabaseControlVm x:Key="ViewModel"/>
</UserControl.Resources>
<Grid DataContext="{StaticResource ViewModel}">
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=OpenDatabaseControl}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />

View File

@@ -12,7 +12,7 @@ namespace ModernKeePass.Views.UserControls
{
public sealed partial class OpenDatabaseUserControl
{
private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Resources["ViewModel"];
private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Grid.DataContext;
public string DatabaseFilePath
{
@@ -52,7 +52,7 @@ namespace ModernKeePass.Views.UserControls
var file = await picker.PickSingleFileAsync();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFilePath = token;
Model.KeyFileText = file.DisplayName;
}

View File

@@ -7,16 +7,14 @@
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:converters="using:ModernKeePass.Converters"
xmlns:viewModels="using:ModernKeePass.ViewModels"
mc:Ignorable="d" >
mc:Ignorable="d">
<UserControl.Resources>
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
<viewModels:SetCredentialsVm x:Key="ViewModel"/>
</UserControl.Resources>
<Grid DataContext="{StaticResource ViewModel}">
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=SetCredentials}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />

View File

@@ -11,7 +11,7 @@ namespace ModernKeePass.Views.UserControls
{
public sealed partial class SetCredentialsUserControl
{
private SetCredentialsVm Model => (SetCredentialsVm)Resources["ViewModel"];
private SetCredentialsVm Model => (SetCredentialsVm)Grid.DataContext;
public string ButtonLabel
{
@@ -44,7 +44,7 @@ namespace ModernKeePass.Views.UserControls
var file = await picker.PickSingleFileAsync();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFilePath = token;
Model.KeyFileText = file.DisplayName;
}
@@ -61,7 +61,7 @@ namespace ModernKeePass.Views.UserControls
var file = await savePicker.PickSaveFileAsync();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFilePath = token;
Model.KeyFileText = file.DisplayName;
await Model.GenerateKeyFile();

View File

@@ -94,8 +94,6 @@
</Compile>
<Compile Include="DependencyInjection.cs" />
<Compile Include="Models\NavigationItem.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />
<Compile Include="Views\MainPageFrames\DonatePage.xaml.cs">
<DependentUpon>DonatePage.xaml</DependentUpon>
</Compile>
@@ -124,7 +122,6 @@
<Compile Include="Views\UserControls\ColorPickerUserControl.xaml.cs">
<DependentUpon>ColorPickerUserControl.xaml</DependentUpon>
</Compile>
<Compile Include="Interfaces\IVmEntity.cs" />
<Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
@@ -140,7 +137,6 @@
<Compile Include="Views\MainPageFrames\WelcomePage.xaml.cs">
<DependentUpon>WelcomePage.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\CompositeKeyVm.cs" />
<Compile Include="Views\EntryDetailPage.xaml.cs">
<DependentUpon>EntryDetailPage.xaml</DependentUpon>
</Compile>