Replace Mediator with Messenger
This commit is contained in:
@@ -6,9 +6,9 @@ using Toolkit.Foundation;
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class ClassicDesktopStyleApplicationHandler :
|
||||
INotificationHandler<NavigateEventArgs<IClassicDesktopStyleApplicationLifetime>>
|
||||
IHandler<NavigateEventArgs<IClassicDesktopStyleApplicationLifetime>>
|
||||
{
|
||||
public Task Handle(NavigateEventArgs<IClassicDesktopStyleApplicationLifetime> args)
|
||||
public void Handle(NavigateEventArgs<IClassicDesktopStyleApplicationLifetime> args)
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is
|
||||
IClassicDesktopStyleApplicationLifetime lifeTime)
|
||||
@@ -19,7 +19,5 @@ public class ClassicDesktopStyleApplicationHandler :
|
||||
window.DataContext = args.Content;
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ using Toolkit.Foundation;
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class ContentControlHandler :
|
||||
INotificationHandler<NavigateEventArgs<ContentControl>>
|
||||
IHandler<NavigateEventArgs<ContentControl>>
|
||||
{
|
||||
public async Task Handle(NavigateEventArgs<ContentControl> args)
|
||||
public void Handle(NavigateEventArgs<ContentControl> args)
|
||||
{
|
||||
if (args.Region is ContentControl contentControl)
|
||||
{
|
||||
@@ -19,10 +19,10 @@ public class ContentControlHandler :
|
||||
control.Loaded -= HandleLoaded;
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
}
|
||||
//if (content is IActivated activated)
|
||||
//{
|
||||
// await activated.OnActivated();
|
||||
//}
|
||||
}
|
||||
|
||||
taskCompletionSource.SetResult();
|
||||
@@ -33,10 +33,10 @@ public class ContentControlHandler :
|
||||
control.Unloaded -= HandleLoaded;
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivated deactivated)
|
||||
{
|
||||
await deactivated.OnDeactivated();
|
||||
}
|
||||
//if (content is IDeactivated deactivated)
|
||||
//{
|
||||
// await deactivated.OnDeactivated();
|
||||
//}
|
||||
|
||||
if (content is IDisposable disposable)
|
||||
{
|
||||
@@ -52,8 +52,6 @@ public class ContentControlHandler :
|
||||
|
||||
contentControl.Content = null;
|
||||
contentControl.Content = control;
|
||||
|
||||
await taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ using Toolkit.UI.Controls.Avalonia;
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class ContentDialogHandler :
|
||||
INotificationHandler<NavigateEventArgs<ContentDialog>>
|
||||
IHandler<NavigateEventArgs<ContentDialog>>
|
||||
{
|
||||
public async Task Handle(NavigateEventArgs<ContentDialog> args)
|
||||
public async void Handle(NavigateEventArgs<ContentDialog> args)
|
||||
{
|
||||
if (args.Template is ContentDialog dialog)
|
||||
{
|
||||
@@ -76,41 +76,33 @@ public class ContentDialogHandler :
|
||||
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
if (!cancelled)
|
||||
{
|
||||
if (content is IDeactivating deactivating)
|
||||
{
|
||||
await deactivating.OnDeactivating();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async void HandleOpened(FluentAvalonia.UI.Controls.ContentDialog sender,
|
||||
void HandleOpened(FluentAvalonia.UI.Controls.ContentDialog sender,
|
||||
EventArgs args)
|
||||
{
|
||||
dialog.Opened -= HandleOpened;
|
||||
if (dialog.DataContext is object content)
|
||||
{
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
}
|
||||
//if (content is IActivated activated)
|
||||
//{
|
||||
// activated.OnActivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
async void HandleClosed(FluentAvalonia.UI.Controls.ContentDialog sender,
|
||||
void HandleClosed(FluentAvalonia.UI.Controls.ContentDialog sender,
|
||||
FluentAvalonia.UI.Controls.ContentDialogClosedEventArgs args)
|
||||
{
|
||||
dialog.Closed -= HandleClosed;
|
||||
if (dialog.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivated deactivated)
|
||||
{
|
||||
await deactivated.OnDeactivated();
|
||||
}
|
||||
//if (content is IDeactivated deactivated)
|
||||
//{
|
||||
// deactivated.OnDeactivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ public class ContentTemplate :
|
||||
control.Loaded -= HandleLoaded;
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
}
|
||||
//if (content is IActivated activated)
|
||||
//{
|
||||
// await activated.OnActivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ public class ContentTemplate :
|
||||
{
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
}
|
||||
//if (content is IActivated activated)
|
||||
//{
|
||||
// await activated.OnActivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ public class ContentTemplate :
|
||||
control.Unloaded -= HandleUnloaded;
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivated deactivated)
|
||||
{
|
||||
await deactivated.OnDeactivated();
|
||||
}
|
||||
//if (content is IDeactivated deactivated)
|
||||
//{
|
||||
// await deactivated.OnDeactivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,10 +92,10 @@ public class ContentTemplate :
|
||||
control.Loaded -= HandleLoaded;
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
}
|
||||
//if (content is IActivated activated)
|
||||
//{
|
||||
// await activated.OnActivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,10 +103,10 @@ public class ContentTemplate :
|
||||
{
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
}
|
||||
//if (content is IActivated activated)
|
||||
//{
|
||||
// await activated.OnActivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,10 +115,10 @@ public class ContentTemplate :
|
||||
control.Unloaded -= HandleUnloaded;
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivated deactivated)
|
||||
{
|
||||
await deactivated.OnDeactivated();
|
||||
}
|
||||
//if (content is IDeactivated deactivated)
|
||||
//{
|
||||
// await deactivated.OnDeactivated();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ using Toolkit.UI.Controls.Avalonia;
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
INotificationHandler<NavigateEventArgs<Frame>>,
|
||||
INotificationHandler<NavigateBackEventArgs<Frame>>
|
||||
IHandler<NavigateEventArgs<Frame>>,
|
||||
IHandler<NavigateBackEventArgs<Frame>>
|
||||
{
|
||||
public Task Handle(NavigateEventArgs<Frame> args)
|
||||
public void Handle(NavigateEventArgs<Frame> args)
|
||||
{
|
||||
if (args.Region is Frame frame)
|
||||
{
|
||||
@@ -32,10 +32,10 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
sender.RemoveHandler(Frame.NavigatedFromEvent, HandleNavigatedFrom);
|
||||
if (sender.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivated deactivated)
|
||||
{
|
||||
await deactivated.OnDeactivated();
|
||||
}
|
||||
//if (content is IDeactivated deactivated)
|
||||
//{
|
||||
// await deactivated.OnDeactivated();
|
||||
//}
|
||||
|
||||
if (content is IDisposable disposable)
|
||||
{
|
||||
@@ -61,10 +61,10 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
|
||||
if (!args.Cancel)
|
||||
{
|
||||
if (content is IDeactivating deactivating)
|
||||
{
|
||||
await deactivating.OnDeactivating();
|
||||
}
|
||||
//if (content is IDeactivating deactivating)
|
||||
//{
|
||||
// await deactivating.OnDeactivating();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,10 +72,10 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
sender.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
|
||||
if (sender.DataContext is object content)
|
||||
{
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
}
|
||||
//if (content is IActivated activated)
|
||||
//{
|
||||
// await activated.OnActivated();
|
||||
//}
|
||||
}
|
||||
|
||||
async void HandleUnloaded(object? _, RoutedEventArgs __)
|
||||
@@ -87,10 +87,10 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
|
||||
if (control.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivated deactivated)
|
||||
{
|
||||
await deactivated.OnDeactivated();
|
||||
}
|
||||
//if (content is IDeactivated deactivated)
|
||||
//{
|
||||
// await deactivated.OnDeactivated();
|
||||
//}
|
||||
|
||||
if (content is IDisposable disposable)
|
||||
{
|
||||
@@ -206,17 +206,13 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(NavigateBackEventArgs<Frame> args)
|
||||
public void Handle(NavigateBackEventArgs<Frame> args)
|
||||
{
|
||||
if (args.Context is Frame frame)
|
||||
{
|
||||
frame.GoBack();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -26,19 +26,20 @@ public static class IServiceCollectionExtensions
|
||||
services.AddTransient<IContentTemplate, ContentTemplate>();
|
||||
services.AddTransient<INavigationRegion, NavigationRegion>();
|
||||
|
||||
services.AddHandler<WriteClipboardHandler>();
|
||||
services.AddHandler<SelectFoldersHandler>();
|
||||
services.AddHandler<SelectFilesHandler>();
|
||||
services.AddAsyncHandler<WriteEventArgs<Clipboard<object>>, WriteClipboardHandler>();
|
||||
services.AddAsyncHandler<SelectionEventArgs<FolderFilter>, IReadOnlyCollection<string>?, SelectFoldersHandler>();
|
||||
services.AddAsyncHandler<SelectionEventArgs<FileFilter>, IReadOnlyCollection<string>?, SelectFilesHandler>();
|
||||
|
||||
services.AddHandler<ClassicDesktopStyleApplicationHandler>(nameof(IClassicDesktopStyleApplicationLifetime));
|
||||
services.AddHandler<SingleViewApplicationHandler>(nameof(ISingleViewApplicationLifetime));
|
||||
services.AddHandler<ContentControlHandler>(nameof(ContentControl));
|
||||
services.AddHandler<NavigateEventArgs<IClassicDesktopStyleApplicationLifetime>, ClassicDesktopStyleApplicationHandler>(nameof(IClassicDesktopStyleApplicationLifetime));
|
||||
services.AddHandler<NavigateEventArgs<ISingleViewApplicationLifetime>, SingleViewApplicationHandler>(nameof(ISingleViewApplicationLifetime));
|
||||
|
||||
services.AddHandler<FrameHandler>(nameof(Frame));
|
||||
services.AddHandler<NavigateEventArgs<ContentControl>, ContentControlHandler>(nameof(ContentControl));
|
||||
|
||||
services.AddHandler<NavigateEventArgs<Frame>, FrameHandler>(nameof(Frame));
|
||||
services.TryAddSingleton<ITransientNavigationStore<Frame>, TransientNavigationStore<Frame>>();
|
||||
|
||||
services.AddHandler<ContentDialogHandler>(nameof(ContentDialog));
|
||||
services.AddHandler<TaskDialogHandler>(nameof(TaskDialog));
|
||||
services.AddHandler<NavigateEventArgs<ContentDialog>, ContentDialogHandler>(nameof(ContentDialog));
|
||||
services.AddHandler<NavigateEventArgs<TaskDialog>, TaskDialogHandler>(nameof(TaskDialog));
|
||||
|
||||
services.AddScoped<INavigationRegionCollection, NavigationRegionCollection>(provider => new NavigationRegionCollection
|
||||
{
|
||||
@@ -64,18 +65,17 @@ public static class IServiceCollectionExtensions
|
||||
|
||||
services.AddTransient<INavigationRegion, NavigationRegion>();
|
||||
|
||||
services.AddHandler<WriteClipboardHandler>();
|
||||
services.AddHandler<SelectFoldersHandler>();
|
||||
services.AddHandler<SelectFilesHandler>();
|
||||
services.AddAsyncHandler<WriteEventArgs<Clipboard<object>>, WriteClipboardHandler>();
|
||||
services.AddAsyncHandler<SelectionEventArgs<FolderFilter>, IReadOnlyCollection<string>?, SelectFoldersHandler>();
|
||||
services.AddAsyncHandler<SelectionEventArgs<FileFilter>, IReadOnlyCollection<string>?, SelectFilesHandler>();
|
||||
|
||||
services.AddHandler<ContentControlHandler>(nameof(ContentControl));
|
||||
services.AddHandler<NavigateEventArgs<ContentControl>, ContentControlHandler>(nameof(ContentControl));
|
||||
|
||||
services.AddHandler<FrameHandler>(nameof(Frame));
|
||||
services.AddHandler<NavigateEventArgs<Frame>, FrameHandler>(nameof(Frame));
|
||||
services.TryAddSingleton<ITransientNavigationStore<Frame>, TransientNavigationStore<Frame>>();
|
||||
|
||||
services.TryAddSingleton(provider.GetRequiredService<ITransientNavigationStore<Frame>>());
|
||||
|
||||
services.AddHandler<ContentDialogHandler>(nameof(ContentDialog));
|
||||
services.AddHandler<TaskDialogHandler>(nameof(TaskDialog));
|
||||
services.AddHandler<NavigateEventArgs<ContentDialog>, ContentDialogHandler>(nameof(ContentDialog));
|
||||
services.AddHandler<NavigateEventArgs<TaskDialog>, TaskDialogHandler>(nameof(TaskDialog));
|
||||
})));
|
||||
|
||||
return services;
|
||||
|
||||
@@ -6,9 +6,9 @@ using Toolkit.Foundation;
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class SingleViewApplicationHandler :
|
||||
INotificationHandler<NavigateEventArgs<ISingleViewApplicationLifetime>>
|
||||
IHandler<NavigateEventArgs<ISingleViewApplicationLifetime>>
|
||||
{
|
||||
public Task Handle(NavigateEventArgs<ISingleViewApplicationLifetime> args)
|
||||
public void Handle(NavigateEventArgs<ISingleViewApplicationLifetime> args)
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is
|
||||
ISingleViewApplicationLifetime lifeTime)
|
||||
@@ -19,7 +19,5 @@ public class SingleViewApplicationHandler :
|
||||
control.DataContext = args.Content;
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ using Toolkit.UI.Controls.Avalonia;
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class TaskDialogHandler(ITopLevelProvider topLevelProvider) :
|
||||
INotificationHandler<NavigateEventArgs<TaskDialog>>
|
||||
IHandler<NavigateEventArgs<TaskDialog>>
|
||||
{
|
||||
public async Task Handle(NavigateEventArgs<TaskDialog> args)
|
||||
public async void Handle(NavigateEventArgs<TaskDialog> args)
|
||||
{
|
||||
if (args.Template is TaskDialog dialog)
|
||||
{
|
||||
@@ -45,10 +45,10 @@ public class TaskDialogHandler(ITopLevelProvider topLevelProvider) :
|
||||
|
||||
if (!cancelled)
|
||||
{
|
||||
if (content is IDeactivating deactivating)
|
||||
{
|
||||
await deactivating.OnDeactivating();
|
||||
}
|
||||
//if (content is IDeactivating deactivating)
|
||||
//{
|
||||
// await deactivating.OnDeactivating();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user