diff --git a/Toolkit.Avalonia/ContentControlHandler.cs b/Toolkit.Avalonia/ContentControlHandler.cs index ccef36e..f159b64 100644 --- a/Toolkit.Avalonia/ContentControlHandler.cs +++ b/Toolkit.Avalonia/ContentControlHandler.cs @@ -49,8 +49,8 @@ public class ContentControlHandler(INavigationContext navigationContext) : control.Loaded += HandleLoaded; control.Unloaded += HandleUnloaded; + control.DataContext = args.Content; contentControl.Content = control; - contentControl.DataContext = args.Content; navigationContext.Set(control); await taskCompletionSource.Task; diff --git a/Toolkit.Foundation/ComponentBuilder.cs b/Toolkit.Foundation/ComponentBuilder.cs index 3afcb6e..35292c5 100644 --- a/Toolkit.Foundation/ComponentBuilder.cs +++ b/Toolkit.Foundation/ComponentBuilder.cs @@ -53,12 +53,19 @@ public class ComponentBuilder : public IComponentBuilder AddConfiguration(Action configurationDelegate) where TConfiguration : ComponentConfiguration, new() { - AddConfiguration(typeof(TConfiguration).Name, configurationDelegate); + TConfiguration configuration = new(); + + if (configurationDelegate is not null) + { + configurationDelegate(configuration); + } + + AddConfiguration(typeof(TConfiguration).Name, configuration); return this; } public IComponentBuilder AddConfiguration(string section, - Action? configurationDelegate = null) + TConfiguration? configuration = null) where TConfiguration : ComponentConfiguration, new() { @@ -68,27 +75,21 @@ public class ComponentBuilder : } configurationRegistered = true; - TConfiguration configuration = new(); - - if (configurationDelegate is not null) - { - configurationDelegate(configuration); - } hostBuilder.ConfigureServices(services => { services.AddConfiguration(section: section, defaultConfiguration: configuration); - services.AddConfiguration(configuration); + services.AddConfiguration(section: section, + defaultConfiguration: configuration); }); return this; } public IComponentBuilder AddConfiguration(string section) - where TConfiguration : - ComponentConfiguration, new() + where TConfiguration : ComponentConfiguration, new() { AddConfiguration(section, null); return this; diff --git a/Toolkit.Foundation/IComponentBuilder.cs b/Toolkit.Foundation/IComponentBuilder.cs index 571f207..a383377 100644 --- a/Toolkit.Foundation/IComponentBuilder.cs +++ b/Toolkit.Foundation/IComponentBuilder.cs @@ -8,7 +8,7 @@ public interface IComponentBuilder where TConfiguration : ComponentConfiguration, new(); IComponentBuilder AddConfiguration(string section, - Action? configurationDelegate = null) + TConfiguration? configuration = null) where TConfiguration : ComponentConfiguration, new(); IComponentBuilder AddConfiguration(string section)