Add KeyBindingBehavior

This commit is contained in:
TheXamlGuy
2024-04-22 22:30:57 +01:00
parent 3e0798f867
commit 79735be033
11 changed files with 82 additions and 72 deletions
-38
View File
@@ -17,47 +17,9 @@
<Style Selector="ui|SettingsExpander /template/ Expander#Expander ToggleButton">
<Setter Property="CornerRadius" Value="{DynamicResource OverlayCornerRadius}" />
</Style>
<Style Selector="Button">
<Setter Property="CornerRadius" Value="{DynamicResource OverlayCornerRadius}" />
</Style>
<Style Selector="TextBox">
<Setter Property="CornerRadius" Value="0" />
<Setter Property="BorderThickness" Value="0 0 0 2" />
<Style Selector="^:focus">
<Style Selector="^ /template/ Border#PART_BorderElement">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0 0 0 2" />
</Style>
</Style>
</Style>
<Style Selector="OverlayPopupHost">
<Setter Property="Template">
<ControlTemplate>
<!-- Do not forget to update Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent test -->
<LayoutTransformControl LayoutTransform="{TemplateBinding Transform}">
<VisualLayerManager IsPopup="True">
<LayoutTransformControl>
<LayoutTransformControl.LayoutTransform>
<ScaleTransform ScaleX="1.4" ScaleY="1.4" />
</LayoutTransformControl.LayoutTransform>
<ContentPresenter
Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</LayoutTransformControl>
</VisualLayerManager>
</LayoutTransformControl>
</ControlTemplate>
</Setter>
</Style>
</Application.Styles>
<Application.Resources>
<Thickness x:Key="TextControlThemePadding">0,5,6,6</Thickness>
<FontFamily x:Key="SymbolFontFamily">avares://HyperX.Launcher.Avalonia/Assets/SegoeIcons.ttf#Segoe Fluent Icons</FontFamily>
<StaticResource x:Key="TextControlBackground" ResourceKey="ControlFillColorTransparentBrush" />
<StaticResource x:Key="TextControlBackgroundPointerOver" ResourceKey="ControlFillColorTransparentBrush" />
<x:Double x:Key="SettingsExpanderItemAdaptiveWidthTrigger">0</x:Double>
<Thickness x:Key="SettingsExpanderItemBottomFooterMargin">0,8,0,0</Thickness>
</Application.Resources>
+1 -2
View File
@@ -36,8 +36,7 @@ public partial class App : Application
services.AddTemplate<MainViewModel, MainView>("Main");
services.AddHandler<MainViewModelHandler>();
services.AddConfiguration<VaultConfiguration>(args => args.Name = "Personal",
$"{nameof(VaultConfiguration)}:Personal");
services.AddConfiguration<VaultConfiguration>(args => args.Name = "Personal", "Vault:Personal");
})
.Build();
+15 -9
View File
@@ -1,9 +1,15 @@
<Window xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Bitvault.Avalonia.LockView"
Title="LockView">
Welcome to Avalonia!
</Window>
<UserControl
x:Class="Bitvault.Avalonia.LockView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox
Width="300"
Classes="revealPasswordButton"
PasswordChar="&#x25CF;">
<TextBox.KeyBindings>
<KeyBinding Gesture="Enter" />
</TextBox.KeyBindings>
</TextBox>
</StackPanel>
</UserControl>
+4 -8
View File
@@ -1,12 +1,8 @@
using Avalonia.Controls;
namespace Bitvault.Avalonia
namespace Bitvault.Avalonia;
public partial class LockView : UserControl
{
public partial class LockView : Window
{
public LockView()
{
InitializeComponent();
}
}
public LockView() => InitializeComponent();
}
+2
View File
@@ -16,5 +16,7 @@ public class VaultComponent :
services.AddTemplate<ArchiveNavigationViewModel, ArchiveNavigationView>();
services.AddTemplate<VaultViewModel, VaultView>("Vault");
services.AddTemplate<LockViewModel, LockView>("Lock");
});
}
+7 -1
View File
@@ -5,4 +5,10 @@
xmlns:vm="using:Bitvault"
x:DataType="vm:VaultNavigationViewModel"
Content="{Binding Name}"
MenuItemsSource="{Binding}" />
MenuItemsSource="{Binding}">
<Interaction.Behaviors>
<EventTriggerBehavior EventName="Loaded">
<NavigateAction Context="Main" Route="Lock" />
</EventTriggerBehavior>
</Interaction.Behaviors>
</NavigationViewItem>
@@ -7,4 +7,11 @@ public class LockViewModel(IServiceProvider serviceProvider,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer) :
ObservableViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer);
ObservableViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer),
IConfirmation
{
public Task<bool> Confirm()
{
return Task.FromResult(false);
}
}
+4 -2
View File
@@ -1,3 +1,5 @@
namespace Bitvault;
using Toolkit.Foundation;
public record Locked;
namespace Bitvault;
public record Locked : INotification;
+4 -2
View File
@@ -1,3 +1,5 @@
namespace Bitvault;
using Toolkit.Foundation;
public record Unlocked;
namespace Bitvault;
public record Unlocked : INotification;
+10 -6
View File
@@ -5,12 +5,13 @@ namespace Bitvault;
public class VaultComponentsInitializer(IServiceProvider provider,
IProxyServiceCollection<IComponentBuilder> proxy,
IEnumerable<IConfiguration<VaultConfiguration>> configurations,
IEnumerable<IConfigurationDescriptor<VaultConfiguration>> configurations,
IComponentScopeCollection scopes,
IVaultHostCollection vaults) : IInitializer
{
public Task Initialize()
public async Task Initialize()
{
foreach (IConfiguration<VaultConfiguration> configuration in configurations)
foreach (IConfigurationDescriptor<VaultConfiguration> configuration in configurations)
{
if (provider.GetRequiredService<IVaultComponent>() is IVaultComponent component)
{
@@ -36,16 +37,19 @@ public class VaultComponentsInitializer(IServiceProvider provider,
provider.GetRequiredService<IComponentScopeProvider>());
services.AddRange(proxy.Services);
services.AddSingleton(new ComponentScope(configuration.Section));
});
builder.AddConfiguration(configuration.Section, configuration.Value);
IComponentHost host = builder.Build();
host.StartAsync();
scopes.Add(new ComponentScopeDescriptor(configuration.Section,
host.Services.GetRequiredService<IServiceProvider>()));
vaults.Add(host);
await host.StartAsync();
}
}
return Task.CompletedTask;
}
}
+27 -3
View File
@@ -5,13 +5,18 @@ namespace Bitvault;
public partial class VaultNavigationViewModel :
ObservableCollectionViewModel<IMainNavigationViewModel>,
IMainNavigationViewModel
IMainNavigationViewModel,
INotificationHandler<Unlocked>,
INotificationHandler<Locked>
{
[ObservableProperty]
private bool locked;
[ObservableProperty]
private string name;
public VaultNavigationViewModel(IServiceProvider serviceProvider,
IServiceFactory serviceFactory,
IServiceFactory serviceFactory,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
@@ -21,11 +26,30 @@ public partial class VaultNavigationViewModel :
Template = template;
Name = name;
}
public IContentTemplate Template { get; set; }
public Task Handle(Unlocked args, CancellationToken cancellationToken = default)
{
Locked = true;
Add<AllNavigationViewModel>();
Add<StarredNavigationViewModel>();
Add<ArchiveNavigationViewModel>();
Add<CategoriesNavigationViewModel>();
return Task.CompletedTask;
}
public IContentTemplate Template { get; set; }
public Task Handle(Locked args, CancellationToken cancellationToken = default)
{
Locked = true;
Clear();
return Task.CompletedTask;
}
}