Added DateEntry element

This commit is contained in:
TheXamlGuy
2024-06-09 13:37:09 +01:00
parent 84e89e1c47
commit 54ae4b6107
6 changed files with 71 additions and 2 deletions
+3 -1
View File
@@ -159,6 +159,7 @@ public partial class App : Application
services.AddTemplate<PasswordEntryViewModel, PasswordEntryView>();
services.AddTemplate<MaskedTextEntryViewModel, MaskedTextEntryView>();
services.AddTemplate<DropdownEntryViewModel, DropdownEntryView>();
services.AddTemplate<DateEntryViewModel, DateEntryView>();
services.AddTemplate<ItemCommandHeaderViewModel, ItemCommandHeaderView>("ItemCommandHeader");
@@ -183,7 +184,8 @@ public partial class App : Application
services.AddHandler<PasswordEntryViewModelHandler>(nameof(PasswordEntryConfiguration));
services.AddHandler<MaskedTextEntryViewModelHandler>(nameof(MaskedTextEntryConfiguration));
services.AddHandler<DropdownEntryViewModelHandler>(nameof(DropdownEntryConfiguration));
services.AddHandler<DateEntryViewModelHandler>(nameof(DateEntryConfiguration));
services.AddHandler<ItemCreatedHandler>(ServiceLifetime.Singleton);
services.AddHandler<ItemModifiedHandler>(ServiceLifetime.Singleton);
});
+11
View File
@@ -0,0 +1,11 @@
<SettingsExpander
x:Class="Bitvault.Avalonia.DateEntryView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Bitvault"
x:DataType="vm:DateEntryViewModel"
Header="{Binding Key}">
<SettingsExpander.Footer>
<DatePicker SelectedDate="{Binding Value}" />
</SettingsExpander.Footer>
</SettingsExpander>
+10
View File
@@ -0,0 +1,10 @@
using Toolkit.UI.Controls.Avalonia;
namespace Bitvault.Avalonia;
public partial class DateEntryView :
SettingsExpander
{
public DateEntryView() =>
InitializeComponent();
}
+15
View File
@@ -0,0 +1,15 @@
using Toolkit.Foundation;
namespace Bitvault;
public partial class DateEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value,
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
+31
View File
@@ -0,0 +1,31 @@
using Toolkit.Foundation;
namespace Bitvault;
public class DateEntryViewModelHandler(IServiceFactory serviceFactory) :
IHandler<CreateEventArgs<DateEntryConfiguration>, IItemEntryViewModel?>
{
public Task<IItemEntryViewModel?> Handle(CreateEventArgs<DateEntryConfiguration> args,
CancellationToken cancellationToken)
{
if (args.Value is DateEntryConfiguration configuration)
{
string? label = configuration.Label;
if (!DateTimeOffset.TryParse($"{configuration.Value}", out DateTimeOffset value))
{
value = DateTimeOffset.Now;
}
double? width = configuration.Width;
if (serviceFactory.Create<DateEntryViewModel>([.. args.Parameters, configuration, label, value, width])
is DateEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
}
}
return Task.FromResult<IItemEntryViewModel?>(default);
}
}
+1 -1
View File
@@ -12,4 +12,4 @@ public partial class TextEntryViewModel(IServiceProvider provider,
ItemEntryConfiguration configuration,
string key,
object value,
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);