Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
fixes for pre12
Browse files Browse the repository at this point in the history
  • Loading branch information
vniehues committed Jan 20, 2022
1 parent c2056ee commit 73f7b91
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/mavvm/Factories/MavvmResolveRouteFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ namespace mavvm
{
public class MavvmResolveRouteFactory<TView, TViewModel> : 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<TViewModel>()
};

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
Expand All @@ -24,7 +46,7 @@ public override Element GetOrCreate()
}

return view;
} 
}
}
}

0 comments on commit 73f7b91

Please sign in to comment.