Tidy up namespaces
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>Toolkit.Foundation.Avalonia</AssemblyName>
|
||||
<RootNamespace>Toolkit.Foundation.Avalonia</RootNamespace>
|
||||
<AssemblyName>Toolkit.Framework.Avalonia</AssemblyName>
|
||||
<RootNamespace>Toolkit.Framework.Avalonia</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.0-preview4" />
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
|
||||
public static class EventArgsExtensions
|
||||
{
|
||||
public static class EventArgsExtensions
|
||||
public static dynamic? GetEventArguments(this EventArgs args, string? path, IValueConverter? converter, object? converterParameter)
|
||||
{
|
||||
public static dynamic? GetEventArguments(this EventArgs args, string? path, IValueConverter? converter, object? converterParameter)
|
||||
return !string.IsNullOrWhiteSpace(path) ? GetEventArgsPropertyPathValue(args, path) : converter is not null ? converter.Convert(args, typeof(object), converterParameter, CultureInfo.CurrentCulture) : (dynamic)args;
|
||||
}
|
||||
|
||||
private static object GetEventArgsPropertyPathValue(object args, string path)
|
||||
{
|
||||
object? value = args;
|
||||
if (path is { })
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(path) ? GetEventArgsPropertyPathValue(args, path) : converter is not null ? converter.Convert(args, typeof(object), converterParameter, CultureInfo.CurrentCulture) : (dynamic)args;
|
||||
value = PropertyPathHelper.GetValue(args, path);
|
||||
}
|
||||
|
||||
private static object GetEventArgsPropertyPathValue(object args, string path)
|
||||
{
|
||||
object? value = args;
|
||||
if (path is { })
|
||||
{
|
||||
value = PropertyPathHelper.GetValue(args, path);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -3,33 +3,32 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
|
||||
public static class IHostBuilderExtensions
|
||||
{
|
||||
public static class IHostBuilderExtensions
|
||||
public static IHostBuilder ConfigureTemplates(this IHostBuilder hostBuilder, Action<ITemplateBuilder> builderDelegate)
|
||||
{
|
||||
public static IHostBuilder ConfigureTemplates(this IHostBuilder hostBuilder, Action<ITemplateBuilder> builderDelegate)
|
||||
hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
|
||||
{
|
||||
hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
|
||||
TemplateBuilder? builder = new();
|
||||
builderDelegate?.Invoke(builder);
|
||||
|
||||
serviceCollection.TryAddSingleton(builder.Descriptors);
|
||||
serviceCollection.TryAddSingleton<ITemplateDescriptorProvider, TemplateDescriptorProvider>();
|
||||
serviceCollection.TryAddSingleton<ITemplateFactory, TemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<INamedTemplateFactory, NamedTemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<ITypedDataTemplateFactory, TypedDataTemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<INamedDataTemplateFactory, NamedDataTemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<ITemplateSelector, TemplateSelector>();
|
||||
|
||||
foreach (ITemplateDescriptor? descriptor in builder.Descriptors)
|
||||
{
|
||||
TemplateBuilder? builder = new();
|
||||
builderDelegate?.Invoke(builder);
|
||||
serviceCollection.Add(new ServiceDescriptor(descriptor.TemplateType, descriptor.TemplateType, descriptor.Lifetime));
|
||||
serviceCollection.Add(new ServiceDescriptor(descriptor.ContentType, descriptor.ContentType, descriptor.Lifetime));
|
||||
}
|
||||
});
|
||||
|
||||
serviceCollection.TryAddSingleton(builder.Descriptors);
|
||||
serviceCollection.TryAddSingleton<ITemplateDescriptorProvider, TemplateDescriptorProvider>();
|
||||
serviceCollection.TryAddSingleton<ITemplateFactory, TemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<INamedTemplateFactory, NamedTemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<ITypedDataTemplateFactory, TypedDataTemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<INamedDataTemplateFactory, NamedDataTemplateFactory>();
|
||||
serviceCollection.TryAddSingleton<ITemplateSelector, TemplateSelector>();
|
||||
|
||||
foreach (ITemplateDescriptor? descriptor in builder.Descriptors)
|
||||
{
|
||||
serviceCollection.Add(new ServiceDescriptor(descriptor.TemplateType, descriptor.TemplateType, descriptor.Lifetime));
|
||||
serviceCollection.Add(new ServiceDescriptor(descriptor.ContentType, descriptor.ContentType, descriptor.Lifetime));
|
||||
}
|
||||
});
|
||||
|
||||
return hostBuilder;
|
||||
}
|
||||
return hostBuilder;
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,18 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static class IServiceCollectionExtensions
|
||||
public static IServiceCollection AddNavigation(this IServiceCollection serviceCollection)
|
||||
{
|
||||
public static IServiceCollection AddNavigation(this IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.TryAddSingleton<INavigationRouteDescriptorCollection, NavigationRouteDescriptorCollection>();
|
||||
serviceCollection.TryAddSingleton<INavigationRouteDescriptorCollection, NavigationRouteDescriptorCollection>();
|
||||
|
||||
serviceCollection.TryAddTransient<Navigation<Frame>, FrameNavigation>();
|
||||
serviceCollection.TryAddTransient<Navigation<ContentDialog>, ContentDialogNavigation>();
|
||||
serviceCollection.TryAddTransient<Navigation<ContentControl>, ContentControlNavigation>();
|
||||
serviceCollection.TryAddTransient<Navigation<Frame>, FrameNavigation>();
|
||||
serviceCollection.TryAddTransient<Navigation<ContentDialog>, ContentDialogNavigation>();
|
||||
serviceCollection.TryAddTransient<Navigation<ContentControl>, ContentControlNavigation>();
|
||||
|
||||
return serviceCollection;
|
||||
}
|
||||
return serviceCollection;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using Avalonia.Data;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia
|
||||
{
|
||||
public static class MarkupExtensions
|
||||
{
|
||||
public static Binding? ToBinding(this object value)
|
||||
{
|
||||
if (value is Binding)
|
||||
{
|
||||
return value as Binding;
|
||||
}
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
|
||||
return new Binding { Mode = BindingMode.OneWay, Source = value };
|
||||
public static class MarkupExtensions
|
||||
{
|
||||
public static Binding? ToBinding(this object value)
|
||||
{
|
||||
if (value is Binding)
|
||||
{
|
||||
return value as Binding;
|
||||
}
|
||||
|
||||
return new Binding { Mode = BindingMode.OneWay, Source = value };
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,27 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Data;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
|
||||
public static class PropertyPathHelper
|
||||
{
|
||||
public static class PropertyPathHelper
|
||||
private static readonly Dummy dummy = new();
|
||||
|
||||
public static object GetValue(object args, string path)
|
||||
{
|
||||
private static readonly Dummy dummy = new();
|
||||
|
||||
public static object GetValue(object args, string path)
|
||||
Binding binding = new(path)
|
||||
{
|
||||
Binding binding = new(path)
|
||||
{
|
||||
Mode = BindingMode.OneTime,
|
||||
Source = args
|
||||
};
|
||||
Mode = BindingMode.OneTime,
|
||||
Source = args
|
||||
};
|
||||
|
||||
dummy.Bind(Dummy.ValueProperty, binding);
|
||||
return dummy.GetValue(Dummy.ValueProperty);
|
||||
}
|
||||
dummy.Bind(Dummy.ValueProperty, binding);
|
||||
return dummy.GetValue(Dummy.ValueProperty);
|
||||
}
|
||||
|
||||
private class Dummy : AvaloniaObject
|
||||
{
|
||||
public static readonly StyledProperty<object> ValueProperty =
|
||||
AvaloniaProperty.Register<Dummy, object>("Value");
|
||||
}
|
||||
private class Dummy : AvaloniaObject
|
||||
{
|
||||
public static readonly StyledProperty<object> ValueProperty =
|
||||
AvaloniaProperty.Register<Dummy, object>("Value");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class CompositeExtension : TriggerExtension
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class EventParameterExtension : MarkupExtension, IEventParameter
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using Avalonia.Markup.Xaml;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class InvokeExtension : TriggerExtension
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using Avalonia.Markup.Xaml;
|
||||
using Mediator;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class NavigateExtension : TriggerExtension
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using Avalonia.Markup.Xaml;
|
||||
using Mediator;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class NavigationRouteExtension : MarkupExtension
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using Avalonia.Data;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class ParameterBindingExtension : MarkupExtension, IParameter
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class TriggerCollection : Collection<Delegate>
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class TriggerExtension : MarkupExtension
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public record ContentControlNavigation : Navigation<ContentControl>
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class ContentControlNavigationHandler : IRequestHandler<ContentControlNavigation, bool>
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using FluentAvalonia.UI.Controls;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public record ContentDialogNavigation : Navigation<ContentDialog>
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class ContentDialogNavigationHandler : IRequestHandler<ContentDialogNavigation, bool>
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using FluentAvalonia.UI.Controls;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public record FrameNavigation : Navigation<Frame>
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using FluentAvalonia.UI.Navigation;
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class FrameNavigationHandler : IRequestHandler<FrameNavigation, bool>
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using FluentAvalonia.UI.Controls;
|
||||
using Mediator;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class NavigateBackHandler : IRequestHandler<NavigateBack>
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using FluentAvalonia.UI.Controls;
|
||||
using Mediator;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class NavigateHandler : IRequestHandler<Navigate>
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public record Navigation<TRoute> : IRequest<bool> where TRoute : TemplatedControl
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Avalonia.Controls;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
internal class NavigationPageFactory : INavigationPageFactory
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using Avalonia.Interactivity;
|
||||
using Mediator;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class NavigationRouteHandler : IRequestHandler<NavigationRoute>
|
||||
{
|
||||
|
||||
@@ -2,37 +2,36 @@
|
||||
using Avalonia.Controls.Templates;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Foundation.Avalonia
|
||||
namespace Toolkit.Foundation.Avalonia;
|
||||
|
||||
public class TemplateSelector : IDataTemplate, ITemplateSelector
|
||||
{
|
||||
public class TemplateSelector : IDataTemplate, ITemplateSelector
|
||||
private readonly Dictionary<object, IControl> dataTracking = new();
|
||||
|
||||
private readonly ITemplateFactory templateFactory;
|
||||
|
||||
public TemplateSelector(ITemplateFactory templateFactory)
|
||||
{
|
||||
private readonly Dictionary<object, IControl> dataTracking = new();
|
||||
this.templateFactory = templateFactory;
|
||||
}
|
||||
|
||||
private readonly ITemplateFactory templateFactory;
|
||||
|
||||
public TemplateSelector(ITemplateFactory templateFactory)
|
||||
public IControl? Build(object? item)
|
||||
{
|
||||
if (item is not null)
|
||||
{
|
||||
this.templateFactory = templateFactory;
|
||||
}
|
||||
|
||||
public IControl? Build(object? item)
|
||||
{
|
||||
if (item is not null)
|
||||
if (dataTracking.TryGetValue(item, out IControl? control))
|
||||
{
|
||||
if (dataTracking.TryGetValue(item, out IControl? control))
|
||||
{
|
||||
return control;
|
||||
}
|
||||
|
||||
return (IControl?)templateFactory.Create(item);
|
||||
return control;
|
||||
}
|
||||
|
||||
return null;
|
||||
return (IControl?)templateFactory.Create(item);
|
||||
}
|
||||
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>Toolkit.Foundation</AssemblyName>
|
||||
<RootNamespace>Toolkit.Foundation</RootNamespace>
|
||||
<AssemblyName>Toolkit.Framework.Foundation</AssemblyName>
|
||||
<RootNamespace>Toolkit.Framework.Foundation</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
namespace Toolkit.Framework.Foundation;
|
||||
|
||||
public interface IEventParameter
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
namespace Toolkit.Framework.Foundation;
|
||||
|
||||
public interface INavigationConfirmation
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user