Finally a workaround the stupid CommandBar DataContext issues

Delete and Restore actions now work as intended
Renamed styles folder
This commit is contained in:
BONNEVILLE Geoffroy
2018-06-22 18:31:55 +02:00
parent a6f82b4541
commit c6e27c35c8
17 changed files with 78 additions and 71 deletions

View File

@@ -1,5 +1,5 @@
using Windows.UI.Xaml; using System.Windows.Input;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml;
using Microsoft.Xaml.Interactivity; using Microsoft.Xaml.Interactivity;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Interfaces; using ModernKeePass.Interfaces;
@@ -20,14 +20,14 @@ namespace ModernKeePass.Actions
DependencyProperty.Register("Entity", typeof(IPwEntity), typeof(DeleteEntityAction), DependencyProperty.Register("Entity", typeof(IPwEntity), typeof(DeleteEntityAction),
new PropertyMetadata(null)); new PropertyMetadata(null));
public Frame Frame public ICommand Command
{ {
get { return (Frame)GetValue(FrameProperty); } get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(FrameProperty, value); } set { SetValue(CommandProperty, value); }
} }
public static readonly DependencyProperty FrameProperty = public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register("Frame", typeof(Frame), typeof(DeleteEntityAction), DependencyProperty.Register("Command", typeof(ICommand), typeof(DeleteEntityAction),
new PropertyMetadata(null)); new PropertyMetadata(null));
public object Execute(object sender, object parameter) public object Execute(object sender, object parameter)
@@ -45,7 +45,7 @@ namespace ModernKeePass.Actions
{ {
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text); ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
Entity.MarkForDelete(resource.GetResourceValue("RecycleBinTitle")); Entity.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
if (Frame.CanGoBack) Frame.GoBack(); Command.Execute(null);
}, null).GetAwaiter(); }, null).GetAwaiter();
return null; return null;

View File

@@ -1,5 +1,5 @@
using Windows.UI.Xaml; using System.Windows.Input;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml;
using Microsoft.Xaml.Interactivity; using Microsoft.Xaml.Interactivity;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Interfaces; using ModernKeePass.Interfaces;
@@ -20,14 +20,14 @@ namespace ModernKeePass.Actions
DependencyProperty.Register("Entity", typeof(IPwEntity), typeof(RestoreEntityAction), DependencyProperty.Register("Entity", typeof(IPwEntity), typeof(RestoreEntityAction),
new PropertyMetadata(null)); new PropertyMetadata(null));
public Frame Frame public ICommand Command
{ {
get { return (Frame)GetValue(FrameProperty); } get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(FrameProperty, value); } set { SetValue(CommandProperty, value); }
} }
public static readonly DependencyProperty FrameProperty = public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register("Frame", typeof(Frame), typeof(RestoreEntityAction), DependencyProperty.Register("Command", typeof(ICommand), typeof(RestoreEntityAction),
new PropertyMetadata(null)); new PropertyMetadata(null));
@@ -38,7 +38,7 @@ namespace ModernKeePass.Actions
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityRestoredTitle"), ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityRestoredTitle"),
resource.GetResourceValue($"{type}Restored")); resource.GetResourceValue($"{type}Restored"));
if (Frame.CanGoBack) Frame.GoBack(); Command.Execute(null);
return null; return null;
} }

View File

@@ -6,12 +6,12 @@
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Colors.xaml" /> <ResourceDictionary Source="ResourceDictionaries/Colors.xaml" />
<ResourceDictionary Source="Styles/TextBoxWithButtonStyle.xaml" /> <ResourceDictionary Source="ResourceDictionaries/TextBoxWithButtonStyle.xaml" />
<ResourceDictionary Source="Styles/HamburgerButtonStyle.xaml" /> <ResourceDictionary Source="ResourceDictionaries/HamburgerButtonStyle.xaml" />
<ResourceDictionary Source="Styles/ListViewLeftIndicatorStyle.xaml" /> <ResourceDictionary Source="ResourceDictionaries/ListViewLeftIndicatorStyle.xaml" />
<ResourceDictionary Source="Styles/NoBorderButtonStyle.xaml" /> <ResourceDictionary Source="ResourceDictionaries/NoBorderButtonStyle.xaml" />
<ResourceDictionary Source="Styles/Styles.xaml" /> <ResourceDictionary Source="ResourceDictionaries/Styles.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>

View File

@@ -23,6 +23,7 @@ namespace ModernKeePass.Interfaces
/// Restore ViewModel /// Restore ViewModel
/// </summary> /// </summary>
ICommand UndoDeleteCommand { get; } ICommand UndoDeleteCommand { get; }
ICommand GoBackCommand { get; set; }
/// <summary> /// <summary>
/// Move a entity to the destination group /// Move a entity to the destination group
/// </summary> /// </summary>

View File

@@ -254,7 +254,7 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Page Include="Styles\Colors.xaml"> <Page Include="ResourceDictionaries\Colors.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -331,27 +331,27 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Styles\HamburgerButtonStyle.xaml"> <Page Include="ResourceDictionaries\HamburgerButtonStyle.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page> </Page>
<Page Include="Styles\ListViewLeftIndicatorStyle.xaml"> <Page Include="ResourceDictionaries\ListViewLeftIndicatorStyle.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page> </Page>
<Page Include="Styles\NoBorderButtonStyle.xaml"> <Page Include="ResourceDictionaries\NoBorderButtonStyle.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page> </Page>
<Page Include="Styles\Styles.xaml"> <Page Include="ResourceDictionaries\Styles.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page> </Page>
<Page Include="Styles\TextBoxWithButtonStyle.xaml"> <Page Include="ResourceDictionaries\TextBoxWithButtonStyle.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@@ -163,6 +163,7 @@ namespace ModernKeePass.ViewModels
public ICommand SaveCommand { get; } public ICommand SaveCommand { get; }
public ICommand GeneratePasswordCommand { get; } public ICommand GeneratePasswordCommand { get; }
public ICommand UndoDeleteCommand { get; } public ICommand UndoDeleteCommand { get; }
public ICommand GoBackCommand { get; set; }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;

View File

@@ -113,6 +113,7 @@ namespace ModernKeePass.ViewModels
public ICommand SortEntriesCommand { get; } public ICommand SortEntriesCommand { get; }
public ICommand SortGroupsCommand { get; } public ICommand SortGroupsCommand { get; }
public ICommand UndoDeleteCommand { get; } public ICommand UndoDeleteCommand { get; }
public ICommand GoBackCommand { get; set; }
private readonly PwGroup _pwGroup; private readonly PwGroup _pwGroup;
private readonly IDatabaseService _database; private readonly IDatabaseService _database;

View File

@@ -273,16 +273,17 @@
Grid.Row="1" Grid.Row="1"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
Margin="{TemplateBinding BorderThickness}" Margin="{TemplateBinding BorderThickness}"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"/>
Grid.RowSpan="1"/>
<Border x:Name="BorderElement" <Border x:Name="BorderElement"
Grid.Row="1" Grid.Row="1"
Grid.Column="0"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"/>
Grid.RowSpan="1"/> <ContentPresenter
<ContentPresenter x:Name="HeaderContentPresenter" x:Name="HeaderContentPresenter"
Grid.Row="0" Grid.Row="0"
Grid.Column="0"
Foreground="{ThemeResource TextBoxForegroundHeaderThemeBrush}" Foreground="{ThemeResource TextBoxForegroundHeaderThemeBrush}"
Margin="0,4,0,4" Margin="0,4,0,4"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"
@@ -291,6 +292,7 @@
FontWeight="Semilight" /> FontWeight="Semilight" />
<ScrollViewer x:Name="ContentElement" <ScrollViewer x:Name="ContentElement"
Grid.Row="1" Grid.Row="1"
Grid.Column="0"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
@@ -302,8 +304,10 @@
IsTabStop="False" IsTabStop="False"
ZoomMode="Disabled" ZoomMode="Disabled"
AutomationProperties.AccessibilityView="Raw"/> AutomationProperties.AccessibilityView="Raw"/>
<ContentControl x:Name="PlaceholderTextContentPresenter" <ContentControl
x:Name="PlaceholderTextContentPresenter"
Grid.Row="1" Grid.Row="1"
Grid.Column="0"
Foreground="{ThemeResource TextBoxPlaceholderTextThemeBrush}" Foreground="{ThemeResource TextBoxPlaceholderTextThemeBrush}"
Margin="{TemplateBinding BorderThickness}" Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}" Padding="{TemplateBinding Padding}"
@@ -367,9 +371,9 @@
</Setter> </Setter>
</Style> </Style>
</Page.Resources> </Page.Resources>
<Page.DataContext> <!--<Page.DataContext>
<viewModels:EntryVm /> <viewModels:EntryVm />
</Page.DataContext> </Page.DataContext>-->
<Page.BottomAppBar> <Page.BottomAppBar>
<CommandBar x:Name="CommandBar" VerticalAlignment="Center"> <CommandBar x:Name="CommandBar" VerticalAlignment="Center">
<CommandBar.SecondaryCommands> <CommandBar.SecondaryCommands>
@@ -380,7 +384,7 @@
</core:EventTriggerBehavior> </core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors> </interactivity:Interaction.Behaviors>
</AppBarButton> </AppBarButton>
<AppBarButton Icon="Save" x:Uid="AppBarSave" Command="{Binding SaveCommand}"> <AppBarButton Icon="Save" x:Uid="AppBarSave" Command="{Binding Path=SaveCommand}">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click"> <core:EventTriggerBehavior EventName="Click">
<core:ChangePropertyAction TargetObject="{Binding ElementName=CommandBar}" PropertyName="IsOpen" Value="False" /> <core:ChangePropertyAction TargetObject="{Binding ElementName=CommandBar}" PropertyName="IsOpen" Value="False" />
@@ -405,14 +409,14 @@
<AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}"> <AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click"> <core:EventTriggerBehavior EventName="Click">
<actions:RestoreEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" /> <actions:RestoreEntityAction Entity="{Binding}" Command="{Binding GoBackCommand}" />
</core:EventTriggerBehavior> </core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors> </interactivity:Interaction.Behaviors>
</AppBarButton> </AppBarButton>
<AppBarButton Icon="Delete" x:Uid="AppBarDelete"> <AppBarButton Icon="Delete" x:Uid="AppBarDelete">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click"> <core:EventTriggerBehavior EventName="Click">
<actions:DeleteEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" /> <actions:DeleteEntityAction Entity="{Binding}" Command="{Binding GoBackCommand}" />
</core:EventTriggerBehavior> </core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors> </interactivity:Interaction.Behaviors>
</AppBarButton> </AppBarButton>

View File

@@ -2,7 +2,6 @@
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; using Windows.UI.Xaml.Navigation;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Services;
using ModernKeePass.ViewModels; using ModernKeePass.ViewModels;
// Pour en savoir plus sur le modèle d'élément Page Détail de l'élément, consultez la page http://go.microsoft.com/fwlink/?LinkId=234232 // Pour en savoir plus sur le modèle d'élément Page Détail de l'élément, consultez la page http://go.microsoft.com/fwlink/?LinkId=234232
@@ -45,6 +44,7 @@ namespace ModernKeePass.Views
NavigationHelper.OnNavigatedTo(e); NavigationHelper.OnNavigatedTo(e);
if (!(e.Parameter is EntryVm)) return; if (!(e.Parameter is EntryVm)) return;
DataContext = (EntryVm)e.Parameter; DataContext = (EntryVm)e.Parameter;
Model.GoBackCommand = NavigationHelper.GoBackCommand;
} }
protected override void OnNavigatedFrom(NavigationEventArgs e) protected override void OnNavigatedFrom(NavigationEventArgs e)

View File

@@ -66,14 +66,14 @@
<AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ShowRestore, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}"> <AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ShowRestore, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click"> <core:EventTriggerBehavior EventName="Click">
<actions:RestoreEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" /> <actions:RestoreEntityAction Entity="{Binding}" Command="{Binding GoBackCommand}" />
</core:EventTriggerBehavior> </core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors> </interactivity:Interaction.Behaviors>
</AppBarButton> </AppBarButton>
<AppBarButton Icon="Delete" x:Uid="AppBarDelete" IsEnabled="{Binding IsNotRoot}" Visibility="{Binding IsSelected, Converter={StaticResource InverseBooleanToVisibilityConverter}}"> <AppBarButton Icon="Delete" x:Uid="AppBarDelete" IsEnabled="{Binding IsNotRoot}" Visibility="{Binding IsSelected, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click"> <core:EventTriggerBehavior EventName="Click">
<actions:DeleteEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" /> <actions:DeleteEntityAction Entity="{Binding}" Command="{Binding GoBackCommand}" />
</core:EventTriggerBehavior> </core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors> </interactivity:Interaction.Behaviors>
</AppBarButton> </AppBarButton>

View File

@@ -7,7 +7,6 @@ using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; using Windows.UI.Xaml.Navigation;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Events; using ModernKeePass.Events;
using ModernKeePass.Services;
using ModernKeePass.ViewModels; using ModernKeePass.ViewModels;
// The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229 // The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229
@@ -57,6 +56,7 @@ namespace ModernKeePass.Views
if (vm != null) if (vm != null)
DataContext = vm; DataContext = vm;
} }
Model.GoBackCommand = NavigationHelper.GoBackCommand;
} }
protected override void OnNavigatedFrom(NavigationEventArgs e) protected override void OnNavigatedFrom(NavigationEventArgs e)