Wrap FluentAvalonia controls within same named classes allowing us to declare the xmlns namespace in our assembly

This commit is contained in:
Daniel Clark
2022-12-10 15:52:58 +00:00
parent 3d9a7e4438
commit 4f243eba2e
94 changed files with 121 additions and 85 deletions
+12
View File
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>Toolkit.Controls.Avalonia</AssemblyName>
<RootNamespace>Toolkit.Controls.Avalonia</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAvaloniaUI" Version="2.0.0-preview4" />
</ItemGroup>
</Project>
+8
View File
@@ -0,0 +1,8 @@
using Avalonia.Styling;
namespace Toolkit.Controls.Avalonia;
public class ContentDialog : FluentAvalonia.UI.Controls.ContentDialog, IStyleable
{
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.ContentDialog);
}
+8
View File
@@ -0,0 +1,8 @@
using Avalonia.Styling;
namespace Toolkit.Controls.Avalonia;
public class Frame : FluentAvalonia.UI.Controls.Frame, IStyleable
{
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.Frame);
}
@@ -0,0 +1,8 @@
using Avalonia.Styling;
namespace Toolkit.Controls.Avalonia;
public class NavigationView : FluentAvalonia.UI.Controls.NavigationView, IStyleable
{
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.NavigationView);
}
@@ -0,0 +1,8 @@
using Avalonia.Styling;
namespace Toolkit.Controls.Avalonia;
public class NavigationViewItem : FluentAvalonia.UI.Controls.NavigationViewItem, IStyleable
{
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.NavigationViewItem);
}
+3
View File
@@ -0,0 +1,3 @@
using Avalonia.Metadata;
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Toolkit.Controls.Avalonia")]
@@ -4,6 +4,8 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>Toolkit.Foundation.Avalonia</AssemblyName>
<RootNamespace>Toolkit.Foundation.Avalonia</RootNamespace>
</PropertyGroup>
<ItemGroup>
@@ -13,7 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
<ProjectReference Include="..\Foundation\Foundation.csproj" />
</ItemGroup>
</Project>
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Mediator;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
@@ -24,7 +25,7 @@ namespace Toolkit.Foundation.Avalonia
foreach (ITemplateDescriptor? descriptor in builder.Descriptors)
{
serviceCollection.Add(new ServiceDescriptor(descriptor.TemplateType, descriptor.TemplateType, descriptor.Lifetime));
serviceCollection.Add(new ServiceDescriptor(descriptor.DataType, descriptor.DataType, descriptor.Lifetime));
serviceCollection.Add(new ServiceDescriptor(descriptor.ContentType, descriptor.ContentType, descriptor.Lifetime));
}
});
@@ -12,18 +12,9 @@ namespace Toolkit.Foundation.Avalonia
async void HandleButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
ContentDialogButtonClickDeferral defferal = args.GetDeferral();
if (sender.DataContext is INavigationConfirmationAsync confirmationAsync)
{
if (!await confirmationAsync.CanConfirmAsync())
{
args.Cancel = true;
}
}
if (sender.DataContext is INavigationConfirmation confirmation)
{
if (!confirmation.CanConfirm())
if (!await confirmation.CanConfirm())
{
args.Cancel = true;
}
@@ -65,29 +65,38 @@ namespace Toolkit.Foundation.Avalonia
if (template is not null)
{
object? route = null;
object? target = null;
if (descriptors.FirstOrDefault(x => request.Route is string { } name && name == x.Name) is NavigationRouteDescriptor descriptor)
{
route = descriptor.Route;
target = descriptor.Route;
}
else
{
route = template;
target = template;
}
if (route is Frame frame)
bool hasNavigated = false;
if (target is Frame frame)
{
await mediator.Send(new FrameNavigation(frame, content, template, keyedParameters));
hasNavigated = await mediator.Send(new FrameNavigation(frame, content, template, keyedParameters));
}
if (route is ContentDialog dialog)
if (target is ContentDialog dialog)
{
await mediator.Send(new ContentDialogNavigation(dialog, content, template, keyedParameters));
hasNavigated = await mediator.Send(new ContentDialogNavigation(dialog, content, template, keyedParameters));
}
if (route is ContentControl contentControl)
if (target is ContentControl contentControl)
{
await mediator.Send(new ContentControlNavigation(contentControl, content, template, keyedParameters));
hasNavigated = await mediator.Send(new ContentControlNavigation(contentControl, content, template, keyedParameters));
}
if (hasNavigated)
{
if (content is INavigated navigated)
{
await navigated.Navigated();
}
}
}
else
@@ -11,6 +11,7 @@ public static class IServiceCollectionExtensions
return serviceCollection;
}
public static IServiceCollection AddFoundation(this IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<IServiceFactory>(provider => new ServiceFactory(provider.GetService, (instanceType, parameters) => ActivatorUtilities.CreateInstance(provider, instanceType, parameters!)))
@@ -4,6 +4,8 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>Toolkit.Foundation</AssemblyName>
<RootNamespace>Toolkit.Foundation</RootNamespace>
</PropertyGroup>
<ItemGroup>
@@ -0,0 +1,13 @@
namespace Toolkit.Foundation
{
public interface INavigationConfirmation
{
ValueTask<bool> CanConfirm();
}
public interface INavigated
{
ValueTask Navigated();
}
}
@@ -4,7 +4,7 @@ namespace Toolkit.Foundation
{
public interface ITemplateDescriptor
{
Type DataType { get; }
Type ContentType { get; }
ServiceLifetime Lifetime { get; }
@@ -23,7 +23,7 @@
if (descriptors.FirstOrDefault(x => x.Name == name) is ITemplateDescriptor descriptor)
{
data = parameters is { Length: > 0 } ? serviceFactory.Create<object>(descriptor.DataType, parameters) : serviceFactory.Create(descriptor.DataType);
data = parameters is { Length: > 0 } ? serviceFactory.Create<object>(descriptor.ContentType, parameters) : serviceFactory.Create(descriptor.ContentType);
if (data is ICache cache)
{
this.cache[name] = cache;
@@ -10,7 +10,7 @@ namespace Toolkit.Foundation
ServiceLifetime lifetime = ServiceLifetime.Transient)
{
TemplateType = templateType;
DataType = dataType;
ContentType = dataType;
Name = name;
Lifetime = lifetime;
}
@@ -19,7 +19,7 @@ namespace Toolkit.Foundation
public Type TemplateType { get; }
public Type DataType { get; }
public Type ContentType { get; }
public string? Name { get; }
}
@@ -21,7 +21,7 @@
public ITemplateDescriptor? Get(Type type)
{
if (descriptors.FirstOrDefault(x => x.DataType == type) is ITemplateDescriptor descriptor)
if (descriptors.FirstOrDefault(x => x.ContentType == type) is ITemplateDescriptor descriptor)
{
return descriptor;
}
@@ -31,7 +31,7 @@
public ITemplateDescriptor? Get<T>()
{
if (descriptors.FirstOrDefault(x => x.DataType == typeof(T)) is ITemplateDescriptor descriptor)
if (descriptors.FirstOrDefault(x => x.ContentType == typeof(T)) is ITemplateDescriptor descriptor)
{
return descriptor;
}
@@ -21,9 +21,9 @@
return data;
}
if (descriptors.FirstOrDefault(x => x.DataType == type) is ITemplateDescriptor descriptor)
if (descriptors.FirstOrDefault(x => x.ContentType == type) is ITemplateDescriptor descriptor)
{
data = parameters is { Length: > 0 } ? serviceFactory.Create<object>(descriptor.DataType, parameters) : serviceFactory.Create(descriptor.DataType);
data = parameters is { Length: > 0 } ? serviceFactory.Create<object>(descriptor.ContentType, parameters) : serviceFactory.Create(descriptor.ContentType);
if (data is ICache cache)
{
this.cache[type] = cache;
@@ -1,7 +0,0 @@
namespace Toolkit.Foundation
{
public interface INavigationConfirmation
{
bool CanConfirm();
}
}
@@ -1,8 +0,0 @@
namespace Toolkit.Foundation
{
public interface INavigationConfirmationAsync
{
Task<bool> CanConfirmAsync();
}
}
@@ -1,30 +0,0 @@
namespace Toolkit.Foundation
{
public class Navigated<TTemplate, TContent> where TTemplate : class where TContent : class
{
public Navigated()
{
}
public Navigated(TTemplate template, TContent content, IDictionary<string, object>? parameters = null)
{
Template = template;
Content = content;
Parameters = parameters;
}
public TTemplate? Template { get; }
public TContent? Content { get; }
public IDictionary<string, object>? Parameters { get; }
}
public class Navigated
{
public static Navigated<TTemplate, TContent> Create<TTemplate, TContent>(TTemplate template, TContent? content, IDictionary<string, object>? parameters = null) where TTemplate : class where TContent : class
{
return new Navigated<TTemplate, TContent>(template, content, parameters);
}
}
}
+25 -10
View File
@@ -3,9 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toolkit.Foundation", "Toolkit.Foundation\Toolkit.Foundation.csproj", "{A3332A95-DF10-4A3F-A500-18513BF1EE2E}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Framework", "Framework", "{B8DD190E-DB19-479B-B614-6160932C2AB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Toolkit.Foundation.Avalonia", "Toolkit.Foundation.Avalonia\Toolkit.Foundation.Avalonia.csproj", "{31217E1F-8F2D-468C-A9DC-839EE9B6F9D4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Foundation", "Framework\Foundation\Foundation.csproj", "{9931E7E1-566A-4306-B243-FEC67128E9B7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia", "Framework\Avalonia\Avalonia.csproj", "{73182B24-1F04-40B5-9C26-4BDD269E998D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Controls", "Controls", "{75BCD316-4955-4CA1-9CB3-F4A65495F5F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia", "Avalonia\Avalonia.csproj", "{13DE3ACD-FEEE-4DDF-B020-6A566701112D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -13,18 +19,27 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3332A95-DF10-4A3F-A500-18513BF1EE2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3332A95-DF10-4A3F-A500-18513BF1EE2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3332A95-DF10-4A3F-A500-18513BF1EE2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3332A95-DF10-4A3F-A500-18513BF1EE2E}.Release|Any CPU.Build.0 = Release|Any CPU
{31217E1F-8F2D-468C-A9DC-839EE9B6F9D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31217E1F-8F2D-468C-A9DC-839EE9B6F9D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31217E1F-8F2D-468C-A9DC-839EE9B6F9D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31217E1F-8F2D-468C-A9DC-839EE9B6F9D4}.Release|Any CPU.Build.0 = Release|Any CPU
{9931E7E1-566A-4306-B243-FEC67128E9B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9931E7E1-566A-4306-B243-FEC67128E9B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9931E7E1-566A-4306-B243-FEC67128E9B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9931E7E1-566A-4306-B243-FEC67128E9B7}.Release|Any CPU.Build.0 = Release|Any CPU
{73182B24-1F04-40B5-9C26-4BDD269E998D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73182B24-1F04-40B5-9C26-4BDD269E998D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73182B24-1F04-40B5-9C26-4BDD269E998D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73182B24-1F04-40B5-9C26-4BDD269E998D}.Release|Any CPU.Build.0 = Release|Any CPU
{13DE3ACD-FEEE-4DDF-B020-6A566701112D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13DE3ACD-FEEE-4DDF-B020-6A566701112D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13DE3ACD-FEEE-4DDF-B020-6A566701112D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13DE3ACD-FEEE-4DDF-B020-6A566701112D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9931E7E1-566A-4306-B243-FEC67128E9B7} = {B8DD190E-DB19-479B-B614-6160932C2AB6}
{73182B24-1F04-40B5-9C26-4BDD269E998D} = {B8DD190E-DB19-479B-B614-6160932C2AB6}
{13DE3ACD-FEEE-4DDF-B020-6A566701112D} = {75BCD316-4955-4CA1-9CB3-F4A65495F5F2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A526C950-2F32-44D7-BF18-331B6B38D52D}
EndGlobalSection