Files
Toolkit2/Toolkit.Foundation/Navigation.cs
T
2025-02-12 20:59:38 +00:00

26 lines
770 B
C#

using CommunityToolkit.Mvvm.Messaging;
namespace Toolkit.Foundation;
public class Navigation(INavigationRegionProvider navigationRegionProvider,
IMessenger messenger) :
INavigation
{
public void Back(object? region)
{
if (region is not null)
{
navigationRegionProvider.TryGet(region, out region);
}
if (region is not null)
{
Type navigationType = region is Type type ? type : region.GetType();
Type navigateType = typeof(NavigateBackEventArgs<>).MakeGenericType(navigationType);
if (Activator.CreateInstance(navigateType, [region]) is object navigate)
{
messenger.Send(navigate, navigationType.Name);
}
}
}
}