This commit is contained in:
TheXamlGuy
2024-06-12 23:04:22 +01:00
parent c8f447251e
commit b155f5c6e2
40 changed files with 262 additions and 249 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ public class ContentControlHandler :
control.Loaded -= HandleLoaded;
if (control.DataContext is object content)
{
if (content is IInitializer initializer)
if (content is IInitialization initializer)
{
await initializer.Initialize();
}
+1 -1
View File
@@ -129,7 +129,7 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
// A hack to wait for the dialog to finish loading up to make it appear more responsive
await Task.Delay(250);
if (content is IInitializer initializer)
if (content is IInitialization initializer)
{
await initializer.Initialize();
}
+4 -4
View File
@@ -16,10 +16,10 @@ public class ContentTemplate :
{
if (observableViewModel.Provider is IServiceProvider provider)
{
IContentTemplateDescriptorProvider? contentTemplateProvider = provider.GetService<IContentTemplateDescriptorProvider>();
INavigationRegion? viewModelContentBinder = provider.GetService<INavigationRegion>();
Type itemType = item.GetType();
if (contentTemplateProvider?.Get(item.GetType().Name) is IContentTemplateDescriptor descriptor)
if (provider.GetRequiredKeyedService<IContentTemplateDescriptor>(itemType.Name.Replace("ViewModel", ""))
is IContentTemplateDescriptor descriptor)
{
if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key) is Control control)
{
@@ -28,7 +28,7 @@ public class ContentTemplate :
control.Loaded -= HandleLoaded;
if (control.DataContext is object content)
{
if (content is IInitializer initializer)
if (content is IInitialization initializer)
{
await initializer.Initialize();
}
+1 -1
View File
@@ -72,7 +72,7 @@ public class FrameHandler :
sender.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
if (sender.DataContext is object content)
{
if (content is IInitializer initializer)
if (content is IInitialization initializer)
{
await initializer.Initialize();
}
@@ -3,6 +3,7 @@ using Avalonia.Controls.ApplicationLifetimes;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Toolkit.Foundation;
using Toolkit.UI.Controls.Avalonia;
namespace Toolkit.Avalonia;
@@ -128,11 +129,11 @@ public static class IServiceCollectionExtensions
services.AddTransient<IContentTemplate, ContentTemplate>();
services.AddTransient<INavigationRegion, NavigationRegion>();
services.AddNavigateHandler<ClassicDesktopStyleApplicationHandler>();
services.AddNavigateHandler<SingleViewApplicationHandler>();
services.AddNavigateHandler<ContentControlHandler>();
services.AddNavigateHandler<FrameHandler>();
services.AddNavigateHandler<ContentDialogHandler>();
services.AddHandler<ClassicDesktopStyleApplicationHandler>(nameof(IClassicDesktopStyleApplicationLifetime));
services.AddHandler<SingleViewApplicationHandler>(nameof(ISingleViewApplicationLifetime));
services.AddHandler<ContentControlHandler>(nameof(ContentControl));
services.AddHandler<FrameHandler>(nameof(Frame));
services.AddHandler<ContentDialogHandler>(nameof(ContentDialog));
services.AddScoped<INavigationRegionCollection, NavigationRegionCollection>(provider => new NavigationRegionCollection
{
@@ -144,15 +145,13 @@ public static class IServiceCollectionExtensions
new ProxyServiceCollection<IComponentBuilder>(services =>
{
services.AddSingleton(provider.GetRequiredService<IDispatcher>());
services.AddTransient<IContentTemplateDescriptorProvider, ContentTemplateDescriptorProvider>();
services.AddTransient<IContentTemplate, ContentTemplate>();
services.AddTransient<INavigationRegion, NavigationRegion>();
services.AddNavigateHandler<ContentControlHandler>();
services.AddNavigateHandler<FrameHandler>();
services.AddNavigateHandler<ContentDialogHandler>();
services.AddHandler<ContentControlHandler>(nameof(ContentControl));
services.AddHandler<FrameHandler>(nameof(Frame));
services.AddHandler<ContentDialogHandler>(nameof(ContentDialog));
})));
return services;