diff --git a/src/mavvm/Factories/MavvmResolveRouteFactory.cs b/src/mavvm/Factories/MavvmResolveRouteFactory.cs index 8437513..1796ba4 100644 --- a/src/mavvm/Factories/MavvmResolveRouteFactory.cs +++ b/src/mavvm/Factories/MavvmResolveRouteFactory.cs @@ -7,6 +7,28 @@ namespace mavvm { public class MavvmResolveRouteFactory : RouteFactory where TView : ContentPage, new() where TViewModel : BindableBase { + + public override Element GetOrCreate(IServiceProvider services) + { + var serviceProvider = services != null ? services : MavvmContainer.ServiceProvider; + + var view = new TView + { + BindingContext = serviceProvider.GetRequiredService() + }; + + 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; + } + public override Element GetOrCreate() { var view = new TView @@ -24,7 +46,7 @@ public override Element GetOrCreate() } return view; - }  + } } }