GroupDetailPage uses navigation service

This commit is contained in:
Geoffroy BONNEVILLE
2020-04-21 13:33:15 +02:00
parent c81f8bc835
commit ac66faa9e2
5 changed files with 70 additions and 46 deletions

View File

@@ -48,7 +48,14 @@
<ColumnDefinition Width="{StaticResource ExpandedMenuGridLength}" x:Name="LeftListViewColumn" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<userControls:HamburgerMenuUserControl x:Uid="GroupsLeftListView" ItemsSource="{Binding Groups}" SelectionChanged="groups_SelectionChanged" ButtonClicked="CreateGroup_ButtonClick" ResizeTarget="{Binding ElementName=LeftListViewColumn}" IsOpen="True" IsButtonVisible="Visible" />
<userControls:HamburgerMenuUserControl
x:Uid="GroupsLeftListView"
ItemsSource="{Binding Groups}"
SelectionChanged="groups_SelectionChanged"
ActionButtonCommand="{Binding CreateGroupCommand}"
ResizeTarget="{Binding ElementName=LeftListViewColumn}"
IsOpen="True"
IsButtonVisible="Visible" />
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@@ -61,7 +68,7 @@
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" x:Uid="ReorderEntriesLabel" Margin="10,10,0,0" Visibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource BodyTextBlockStyle}" />
<!--<TextBlock Grid.Column="1" Grid.Row="0" x:Uid="EntrySymbol" Margin="40,20,0,0" Visibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource BodyTextBlockStyle}" />-->
<HyperlinkButton Grid.Column="2" Grid.Row="0" VerticalAlignment="Top" Click="CreateEntry_ButtonClick" HorizontalAlignment="Right" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}">
<HyperlinkButton Grid.Column="2" Grid.Row="0" VerticalAlignment="Top" Command="{Binding CreateEntryCommand}" HorizontalAlignment="Right" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}">
<StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="Add">
<ToolTipService.ToolTip>

View File

@@ -5,6 +5,7 @@ using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using GalaSoft.MvvmLight.Views;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Entry.Models;
@@ -24,6 +25,7 @@ namespace ModernKeePass.Views
public sealed partial class GroupDetailPage
{
private readonly IResourceProxy _resource;
private readonly INavigationService _navigation;
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
@@ -32,11 +34,12 @@ namespace ModernKeePass.Views
public NavigationHelper NavigationHelper { get; }
public GroupDetailVm Model => (GroupDetailVm)DataContext;
public GroupDetailPage(): this (App.Services.GetRequiredService<IResourceProxy>()) { }
public GroupDetailPage(IResourceProxy resource)
public GroupDetailPage(): this (App.Services.GetRequiredService<IResourceProxy>(), App.Services.GetRequiredService<INavigationService>()) { }
public GroupDetailPage(IResourceProxy resource, INavigationService navigation)
{
InitializeComponent();
_resource = resource;
_navigation = navigation;
NavigationHelper = new NavigationHelper(this);
}
@@ -84,7 +87,7 @@ namespace ModernKeePass.Views
return;
default:
var group = listView?.SelectedItem as Application.Group.Models.GroupVm;
Frame.Navigate(typeof(GroupDetailPage), new NavigationItem { Id = group?.Id });
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = group?.Id });
break;
}
}
@@ -97,7 +100,7 @@ namespace ModernKeePass.Views
return;
default:
var entry = GridView.SelectedItem as EntryVm;
Frame.Navigate(typeof(EntryDetailPage), new NavigationItem { Id = entry?.Id });
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem { Id = entry?.Id });
break;
}
}
@@ -110,22 +113,6 @@ namespace ModernKeePass.Views
e.DestinationItem.Item = e.SourceItem.Item;
}
}
private async void CreateEntry_ButtonClick(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(EntryDetailPage), new NavigationItem
{
Id = await Model.AddNewEntry(),
IsNew = true
});
}
private async void CreateGroup_ButtonClick(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(GroupDetailPage), new NavigationItem
{
Id = await Model.AddNewGroup(),
IsNew = true
});
}
private void GridView_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
@@ -145,7 +132,7 @@ namespace ModernKeePass.Views
private void SearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
{
Frame.Navigate(typeof(EntryDetailPage), new NavigationItem { Id = args.Tag });
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem { Id = args.Tag });
}
private void GroupDetailPage_OnSizeChanged(object sender, SizeChangedEventArgs e)

View File

@@ -72,7 +72,15 @@
<DataTemplate>
<StackPanel Orientation="Vertical">
<Border BorderBrush="White" BorderThickness="0,0,0,1" />
<Button Padding="0" Height="{StaticResource MenuSize}" Margin="0" Visibility="{Binding IsButtonVisible, ElementName=UserControl}" Style="{StaticResource NoBorderButtonStyle}" Background="Transparent" BorderThickness="0" Width="{StaticResource ExpandedMenuSize}" HorizontalContentAlignment="Left" Click="ButtonBase_OnClick">
<Button Padding="0" Margin="0"
Height="{StaticResource MenuSize}"
Visibility="{Binding IsButtonVisible, ElementName=UserControl}"
Style="{StaticResource NoBorderButtonStyle}"
Background="Transparent"
BorderThickness="0"
Width="{StaticResource ExpandedMenuSize}"
HorizontalContentAlignment="Left"
Command="{Binding ActionButtonCommand, ElementName=UserControl}">
<StackPanel Orientation="Horizontal" Margin="17,0,5,0">
<SymbolIcon Symbol="Add">
<ToolTipService.ToolTip>

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight.Command;
using ModernKeePass.Application.Common.Interfaces;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
@@ -124,16 +125,23 @@ namespace ModernKeePass.Views.UserControls
typeof(HamburgerMenuUserControl),
new PropertyMetadata(false, (o, args) => { }));
public RelayCommand ActionButtonCommand
{
get { return (RelayCommand)GetValue(ActionButtonCommandProperty); }
set { SetValue(ActionButtonCommandProperty, value); }
}
public static readonly DependencyProperty ActionButtonCommandProperty =
DependencyProperty.Register(
nameof(ActionButtonCommand),
typeof(RelayCommand),
typeof(HamburgerMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectionChanged?.Invoke(sender, e);
}
public event EventHandler<RoutedEventArgs> ButtonClicked;
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
ButtonClicked?.Invoke(sender, e);
}
}
}