Improve Publisher

This commit is contained in:
TheXamlGuy
2024-05-14 19:24:07 +01:00
parent 06be638af8
commit 819d796c16
22 changed files with 91 additions and 58 deletions
+4
View File
@@ -98,8 +98,12 @@ public partial class App : Application
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
services.AddHandler<CreateItemHandler>(ServiceLifetime.Singleton);
services.AddHandler<ItemActivatedHandler>();
services.AddScoped<IValueStore<Item>, ValueStore<Item>>();
services.AddHandler<ArchiveItemHandler>(ServiceLifetime.Scoped);
});
})!);
+5 -3
View File
@@ -9,16 +9,18 @@ namespace Bitvault.Avalonia;
public class AppHandler(IPublisher publisher) :
INotificationHandler<StartedEventArgs>
{
public async Task Handle(StartedEventArgs args, CancellationToken cancellationToken = default)
public Task Handle(StartedEventArgs args)
{
if (Application.Current is Application application)
{
if (application.ApplicationLifetime is IApplicationLifetime lifetime)
{
await publisher.Publish(new NavigateEventArgs(lifetime is IClassicDesktopStyleApplicationLifetime ? "MainWindow" : "Main",
publisher.Publish(new NavigateEventArgs(lifetime is IClassicDesktopStyleApplicationLifetime ? "MainWindow" : "Main",
lifetime is IClassicDesktopStyleApplicationLifetime ? typeof(IClassicDesktopStyleApplicationLifetime) :
typeof(ISingleViewApplicationLifetime)), cancellationToken);
typeof(ISingleViewApplicationLifetime)));
}
}
return Task.CompletedTask;
}
}
@@ -10,6 +10,7 @@
VerticalAlignment="Center"
Command="{Binding InvokeCommand}"
Foreground="{DynamicResource IconForegroundBrush}"
HotKey="Delete"
ToolTip.Tip="Archive">
<TextBlock
VerticalAlignment="Center"