diff --git a/samples/mavvmApp/ViewModels/SecondPageViewModel.cs b/samples/mavvmApp/ViewModels/SecondPageViewModel.cs index 9f39e09..f44f34f 100644 --- a/samples/mavvmApp/ViewModels/SecondPageViewModel.cs +++ b/samples/mavvmApp/ViewModels/SecondPageViewModel.cs @@ -3,11 +3,12 @@ using Microsoft.Maui.Controls; using Microsoft.Maui.Hosting; using mavvm; +using mavvm.Interfaces; namespace mavvmApp.ViewModels { [QueryProperty(nameof(Count), "countParam")] - public class SecondPageViewModel : BindableBase + public class SecondPageViewModel : BindableBase, IPageAware { string _title; public string Title @@ -54,6 +55,16 @@ async void LogCount() var optionAlert = await BaseMethods.ShowAlert("Count", $"Count is {Count}", "Cancel", "Ok"); _consoleService.Log(optionAlert.ToString()); } + + public void Appearing() + { + _consoleService.Log("Appearing"); + } + + public void Disappearing() + { + _consoleService.Log("Disappearing"); + } } } diff --git a/src/mavvm/Factories/MavvmResolveRouteFactory.cs b/src/mavvm/Factories/MavvmResolveRouteFactory.cs index f6311ad..8437513 100644 --- a/src/mavvm/Factories/MavvmResolveRouteFactory.cs +++ b/src/mavvm/Factories/MavvmResolveRouteFactory.cs @@ -1,4 +1,5 @@ using System; +using mavvm.Interfaces; using Microsoft.Extensions.DependencyInjection; using Microsoft.Maui.Controls; @@ -13,11 +14,14 @@ public override Element GetOrCreate() BindingContext = MavvmContainer.ServiceProvider.GetRequiredService() }; - //if (view.BindingContext is IPageAware pageAware) - //{ - // view.Disappearing += (s, e) => pageAware.Disappearing(); - // view.Appearing += (s, e) => pageAware.Appearing(); - //} + if (view.BindingContext is IPageAware pageAware) + { + view.Disappearing -= (s, e) => pageAware.Disappearing(); + view.Appearing -= (s, e) => pageAware.Appearing(); + + view.Disappearing += (s, e) => pageAware.Disappearing(); + view.Appearing += (s, e) => pageAware.Appearing(); + } return view; }  diff --git a/src/mavvm/Interfaces/IPageAware.cs b/src/mavvm/Interfaces/IPageAware.cs new file mode 100644 index 0000000..8430b8f --- /dev/null +++ b/src/mavvm/Interfaces/IPageAware.cs @@ -0,0 +1,10 @@ +using System; +namespace mavvm.Interfaces +{ + public interface IPageAware + { + void Appearing(); + void Disappearing(); + } +} + diff --git a/src/mavvm/mavvm.csproj b/src/mavvm/mavvm.csproj index 8e0eebc..6e89dce 100644 --- a/src/mavvm/mavvm.csproj +++ b/src/mavvm/mavvm.csproj @@ -12,7 +12,7 @@ 21.0 10.0.18362.0 mavvm - 0.9.4 + 0.9.5 Vincent Niehues Vincent Niehues 2021 Vincent Niehues @@ -28,10 +28,12 @@ It uses the Shell we all know from xamarin together with the all new .net maui w + +