Add Navigations

This commit is contained in:
Daniel Clark
2022-12-05 18:52:37 +00:00
parent 3b09265a30
commit 855a4b98d2
24 changed files with 532 additions and 1 deletions
@@ -0,0 +1,38 @@
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
namespace Toolkit.Foundation.Avalonia
{
public class NavigationRoute : INavigationRoute
{
private readonly INavigationRouteDescriptorCollection routes;
public NavigationRoute(INavigationRouteDescriptorCollection 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 INavigationRouteDescriptor descriptor)
{
routes.Remove(descriptor);
}
}
control.Unloaded += HandleUnloaded;
}
if (routes.FirstOrDefault(x => x.Name == name) is INavigationRouteDescriptor descriptor)
{
routes.Remove(descriptor);
}
routes.Add(new NavigationRouteDescriptor(name, route));
}
}
}