Main page now uses Frame to change views when selecting items

Backgrounds unified
Menu items can be disabled thanks to custom ListView control
This commit is contained in:
2017-09-27 18:01:21 +02:00
committed by BONNEVILLE Geoffroy
parent 3a045dbb16
commit caaf34918e
19 changed files with 319 additions and 138 deletions

View File

@@ -1,7 +1,6 @@
using System;
using Windows.UI.Xaml;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using ModernKeePass.Models;
using ModernKeePass.Pages;
using ModernKeePass.ViewModels;
@@ -17,70 +16,26 @@ namespace ModernKeePass
public MainPage()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
picker.SuggestedStartLocation =
Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
picker.FileTypeFilter.Add(".kdbx");
var file = await picker.PickSingleFileAsync();
if (file != null)
var mainMenuItems = new ObservableCollection<MainMenuItem>
{
// Application now has read/write access to the picked file
//DataContext = new DatabaseVm(file);
((App)Application.Current).Database = new Common.DatabaseHelper(file);
var homeVm = DataContext as HomeVm;
homeVm.Visibility = Visibility.Visible;
homeVm.NotifyPropertyChanged("Visibility");
}
new MainMenuItem {Title = "File", PageType = typeof(OpenDatabasePage)},
new MainMenuItem {Title = "New" /*, PageType = typeof(NewDatabasePage)*/},
new MainMenuItem {Title = "Save" , PageType = typeof(SaveDatabasePage)},
new MainMenuItem {Title = "Recent files - Coming soon" /*, PageType = typeof(RecentDatabasesPage)*/},
new MainMenuItem {Title = "Url files - Coming soon" /*, PageType = typeof(OpenUrlPage)*/}
};
DataContext = new MainVm {MainMenuItems = mainMenuItems};
MenuListView.SelectedIndex = -1;
}
private void openBbutton_Click(object sender, RoutedEventArgs e)
{
/*var database = DataContext as DatabaseVm;
database.Open();
if (database.IsOpen)
Frame.Navigate(typeof(GroupDetailPage), database.RootGroup);*/
var homeVm = DataContext as HomeVm;
var app = ((App)Application.Current);
homeVm.ErrorMessage = app.Database.Open(homeVm.Password);
if (!string.IsNullOrEmpty(homeVm.ErrorMessage)) homeVm.NotifyPropertyChanged("ErrorMessage");
else Frame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
}
private void saveBbutton_Click(object sender, RoutedEventArgs e)
{
var database = DataContext as HomeVm;
((App)Application.Current).Database.Save();
}
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Contains(SelectItem) || e.AddedItems.Contains(NewItem))
{
SelectGrid.Visibility = Visibility.Visible;
SaveButton.Visibility = Visibility.Collapsed;
}
else if (e.AddedItems.Contains(SaveItem))
{
SaveButton.Visibility = Visibility.Visible;
SelectGrid.Visibility = Visibility.Collapsed;
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var app = (App)Application.Current;
if (app.Database == null) return;
var homeVm = DataContext as HomeVm;
homeVm.IsOpen = app.Database.IsOpen;
homeVm.NotifyPropertyChanged("IsOpen");
if (Frame == null) return;
var listView = sender as ListView;
if (listView == null) return;
if (listView.SelectedIndex == -1) return;
var selectedItem = listView.SelectedItem as MainMenuItem;
if (selectedItem != null) MenuFrame.Navigate(selectedItem.PageType, Frame);
}
}
}