@@ -68,33 +68,44 @@ public virtual void ScrollIntoView(NavigationContext item)
6868 protected IView ? ResolveView ( NavigationContext context )
6969 {
7070 var view = context . View ;
71+ INavigationAware ? navigationAware ;
72+
7173 if ( view is null )
7274 {
7375 view = context . ServiceProvider . GetRequiredKeyedService < IView > ( context . ViewName ) ;
74- var navigationAware = context . ServiceProvider . GetRequiredKeyedService < INavigationAware > ( context . ViewName ) ;
75-
76- if ( Current . TryTakeData ( out var previousData ) )
77- {
78- previousData . NavigationAware . OnNavigatedFrom ( context ) ;
79- }
76+ navigationAware = context . ServiceProvider . GetRequiredKeyedService < INavigationAware > ( context . ViewName ) ;
8077
8178 view . DataContext = navigationAware ;
82- navigationAware . OnNavigatedTo ( context ) ;
83- context . Alias = navigationAware . Alias ;
79+
8480 if ( navigationAware is ICanUnload canUnloadNavigationAware )
8581 {
8682 canUnloadNavigationAware . RequestUnload += ( ) =>
8783 {
8884 DeActivate ( context ) ;
8985 } ;
9086 }
91- Current . SetData ( ( view , navigationAware ) ) ;
87+
9288 context . View = view ;
9389 ViewCache . AddOrUpdate ( context , view , ( key , value ) => view ) ;
9490 }
91+ else
92+ {
93+ navigationAware = view . DataContext as INavigationAware
94+ ?? context . ServiceProvider . GetRequiredKeyedService < INavigationAware > ( context . ViewName ) ;
95+ }
96+
97+ context . Alias = navigationAware ? . Alias ;
98+ if ( Current . TryTakeData ( out var previousData ) )
99+ {
100+ previousData . NavigationAware . OnNavigatedFrom ( context ) ;
101+ }
102+ navigationAware ? . OnNavigatedTo ( context ) ;
103+ Current . SetData ( ( view , navigationAware ! ) ) ;
104+
95105 return view ;
96106 }
97107
108+
98109 protected virtual void WhenContextsAdded ( IEnumerable < NavigationContext > contexts )
99110 {
100111
0 commit comments