Add project files.

This commit is contained in:
Daniel Clark
2022-11-01 15:26:08 +00:00
parent daa7b59f22
commit 7e4f880821
408 changed files with 16863 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
namespace TheXamlGuy.Framework.Avalonia;
public class Router : IRouter
{
private readonly IRouteDescriptorCollection routes;
public Router(IRouteDescriptorCollection routes)
{
this.routes = routes;
}
public void Add(string name, object route)
{
if (route is TemplatedControl control)
{
void HandleUnloaded(object? sender, RoutedEventArgs args)
{
if (routes.FirstOrDefault(x => x.Route == sender) is IRouteDescriptor descriptor)
{
routes.Remove(descriptor);
}
}
control.Unloaded += HandleUnloaded;
}
if (routes.FirstOrDefault(x => x.Name == name) is IRouteDescriptor descriptor)
{
routes.Remove(descriptor);
}
routes.Add(new RouteDescriptor(name, route));
}
}