Files
modernkeepass/ModernKeePass/MainPage.xaml.cs

49 lines
2.2 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
using System.Linq;
using Windows.UI.Xaml;
2017-09-10 13:49:11 -04:00
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using ModernKeePass.Pages;
using ModernKeePass.ViewModels;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
2017-09-10 13:49:11 -04:00
namespace ModernKeePass
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
2017-09-10 13:49:11 -04:00
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
2017-09-26 18:18:00 +02:00
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
2017-09-11 18:25:00 +02:00
{
new MainMenuItemVm {Title = "Open", PageType = typeof(OpenDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Page2},
new MainMenuItemVm {Title = "New" /*, PageType = typeof(NewDatabasePage)*/, Destination = MenuFrame, SymbolIcon = Symbol.Add},
new MainMenuItemVm {Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Save},
new MainMenuItemVm {Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Copy}
};
var app = (App)Application.Current;
if (app.Database != null && app.Database.IsOpen)
mainMenuItems.Add(new MainMenuItemVm { Title = app.Database.Name, PageType = typeof(GroupDetailPage), Destination = Frame, Parameter = app.Database.RootGroup, Group = 1, SymbolIcon = Symbol.ProtectedDocument});
var mainVm = DataContext as MainVm;
mainVm.MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
mainVm.NotifyPropertyChanged("MainMenuItems");
2017-09-11 18:25:00 +02:00
}
2017-09-20 18:19:00 +02:00
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var mainMenuItem = e.AddedItems[0] as MainMenuItemVm;
mainMenuItem?.Destination.Navigate(mainMenuItem.PageType, mainMenuItem.Parameter);
}
2017-09-10 13:49:11 -04:00
}
}