This commit is contained in:
TheXamlGuy
2024-06-15 14:24:30 +01:00
parent 370e6bf96b
commit 7a811acde5
11 changed files with 32 additions and 26 deletions
@@ -6,7 +6,7 @@ using Toolkit.Foundation;
namespace Toolkit.Avalonia; namespace Toolkit.Avalonia;
public class ClassicDesktopStyleApplicationHandler : public class ClassicDesktopStyleApplicationHandler :
INavigateHandler<IClassicDesktopStyleApplicationLifetime> INotificationHandler<NavigateEventArgs<IClassicDesktopStyleApplicationLifetime>>
{ {
public Task Handle(NavigateEventArgs<IClassicDesktopStyleApplicationLifetime> args) public Task Handle(NavigateEventArgs<IClassicDesktopStyleApplicationLifetime> args)
{ {
+1 -6
View File
@@ -5,7 +5,7 @@ using Toolkit.Foundation;
namespace Toolkit.Avalonia; namespace Toolkit.Avalonia;
public class ContentControlHandler : public class ContentControlHandler :
INavigateHandler<ContentControl> INotificationHandler<NavigateEventArgs<ContentControl>>
{ {
public async Task Handle(NavigateEventArgs<ContentControl> args) public async Task Handle(NavigateEventArgs<ContentControl> args)
{ {
@@ -19,11 +19,6 @@ public class ContentControlHandler :
control.Loaded -= HandleLoaded; control.Loaded -= HandleLoaded;
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
if (content is IInitialization initializer)
{
await initializer.Initialize();
}
if (content is IActivated activated) if (content is IActivated activated)
{ {
await activated.OnActivated(); await activated.OnActivated();
+1 -1
View File
@@ -5,7 +5,7 @@ using Toolkit.UI.Controls.Avalonia;
namespace Toolkit.Avalonia; namespace Toolkit.Avalonia;
public class ContentDialogHandler(IDispatcher dispatcher) : public class ContentDialogHandler(IDispatcher dispatcher) :
INavigateHandler<ContentDialog> INotificationHandler<NavigateEventArgs<ContentDialog>>
{ {
public async Task Handle(NavigateEventArgs<ContentDialog> args) public async Task Handle(NavigateEventArgs<ContentDialog> args)
{ {
+2 -2
View File
@@ -8,8 +8,8 @@ using Toolkit.UI.Controls.Avalonia;
namespace Toolkit.Avalonia; namespace Toolkit.Avalonia;
public class FrameHandler : public class FrameHandler :
INavigateHandler<Frame>, INotificationHandler<NavigateEventArgs<Frame>>,
INavigateBackHandler<Frame> INotificationHandler<NavigateBackEventArgs<Frame>>
{ {
public Task Handle(NavigateEventArgs<Frame> args) public Task Handle(NavigateEventArgs<Frame> args)
{ {
@@ -6,7 +6,7 @@ using Toolkit.Foundation;
namespace Toolkit.Avalonia; namespace Toolkit.Avalonia;
public class SingleViewApplicationHandler : public class SingleViewApplicationHandler :
INavigateHandler<ISingleViewApplicationLifetime> INotificationHandler<NavigateEventArgs<ISingleViewApplicationLifetime>>
{ {
public Task Handle(NavigateEventArgs<ISingleViewApplicationLifetime> args) public Task Handle(NavigateEventArgs<ISingleViewApplicationLifetime> args)
{ {
+7 -1
View File
@@ -25,7 +25,13 @@ public class ContentFactory(IMediator mediator,
initialization.Initialize(); initialization.Initialize();
} }
}, parameters) }, parameters)
: provider.GetRequiredKeyedService(descriptor.ContentType, descriptor.Key); : provider.GetRequiredKeyedService(descriptor.ContentType, args =>
{
if (args is IInitialization initialization)
{
initialization.Initialize();
}
}, descriptor.Key);
return content; return content;
} }
@@ -1,5 +0,0 @@
namespace Toolkit.Foundation;
public interface INavigateBackHandler<TNavigation> :
INotificationHandler<NavigateBackEventArgs<TNavigation>>,
INavigateHandler;
-7
View File
@@ -1,7 +0,0 @@
namespace Toolkit.Foundation;
public interface INavigateHandler;
public interface INavigateHandler<TNavigation> :
INotificationHandler<NavigateEventArgs<TNavigation>>,
INavigateHandler;
@@ -0,0 +1,17 @@
using Microsoft.Extensions.DependencyInjection;
namespace Toolkit.Foundation;
public static class IServiceProviderExtensions
{
public static object GetRequiredKeyedService(this IServiceProvider provider,
Type serviceType,
Action<object> serviceDelegate,
object? serviceKey)
{
object service = provider.GetRequiredKeyedService(serviceType, serviceKey);
serviceDelegate.Invoke(service);
return service;
}
}
+1 -1
View File
@@ -96,7 +96,7 @@ public class NavigationScope(IServiceProvider provider,
Type navigateType = typeof(NavigateBackEventArgs<>).MakeGenericType(navigationType); Type navigateType = typeof(NavigateBackEventArgs<>).MakeGenericType(navigationType);
if (Activator.CreateInstance(navigateType, [region]) is object navigate) if (Activator.CreateInstance(navigateType, [region]) is object navigate)
{ {
publisher.Publish(navigate); publisher.Publish(navigate, navigationType.Name);
} }
} }
} }
+1 -1
View File
@@ -403,7 +403,7 @@ public partial class ObservableCollection<TItem> :
IsCompatibleObject(value) ? IsCompatibleObject(value) ?
IndexOf((TItem)value!) : -1; IndexOf((TItem)value!) : -1;
public Task Initialize() public virtual Task Initialize()
{ {
if (Initialized) if (Initialized)
{ {