Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Lemon.ModuleNavigation.SampleViewModel;

public class BaseNavigationViewModel : ReactiveObject, INavigationAware
public class BaseNavigationViewModel : ReactiveObject, INavigationAware, ICanUnload
{
public virtual string Greeting => $"Welcome to {GetType().Name}[{Environment.ProcessId}][{Environment.CurrentManagedThreadId}]{Environment.NewLine}{DateTime.Now:yyyy-MM-dd HH-mm-ss.ffff}";

Expand Down
18 changes: 12 additions & 6 deletions src/Lemon.ModuleNavigation.Avaloniaui/Regions/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ public virtual void ScrollIntoView(NavigationContext item)

view.DataContext = navigationAware;
navigationAware.OnNavigatedTo(context);
navigationAware.RequestUnload += () =>
if (navigationAware is ICanUnload canUnloadNavigationAware)
{
DeActivate(context);
};
canUnloadNavigationAware.RequestUnload += () =>
{
DeActivate(context);
};
}
Current.SetData((view, navigationAware));
context.View = view;
ViewCache.AddOrUpdate(context, view, (key, value) => view);
Expand Down Expand Up @@ -137,10 +140,13 @@ private IDataTemplate CreateRegionDataTemplate()

view.DataContext = navigationAware;
navigationAware.OnNavigatedTo(context);
navigationAware.RequestUnload += () =>
if (navigationAware is ICanUnload canUnloadNavigationAware)
{
DeActivate(context);
};
canUnloadNavigationAware.RequestUnload += () =>
{
DeActivate(context);
};
}
Current.SetData((view, navigationAware));
context.View = view;
ViewCache.AddOrUpdate(context, view, (key, value) => view);
Expand Down
9 changes: 6 additions & 3 deletions src/Lemon.ModuleNavigation.Wpf/Regions/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ public virtual void ScrollIntoView(NavigationContext item)

view.DataContext = navigationAware;
navigationAware.OnNavigatedTo(context);
navigationAware.RequestUnload += () =>
if (navigationAware is ICanUnload canUnloadNavigationAware)
{
DeActivate(context);
};
canUnloadNavigationAware.RequestUnload += () =>
{
DeActivate(context);
};
}
Current.SetData((view, navigationAware));
context.View = view;
ViewCache.AddOrUpdate(context, view, (key, value) => view);
Expand Down
6 changes: 6 additions & 0 deletions src/Lemon.ModuleNavigation/Abstractions/ICanUnload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Lemon.ModuleNavigation.Abstractions;

public interface ICanUnload
{
event Action? RequestUnload;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public interface INavigationAware
{
event Action? RequestUnload;
void OnNavigatedTo(NavigationContext navigationContext);
bool IsNavigationTarget(NavigationContext navigationContext);
void OnNavigatedFrom(NavigationContext navigationContext);
Expand Down