Upgrading from 7.2 to 8.0 breaks the way my Tab Page Viewmodels are called and bound.
Clone this repo with a simple XF + Prism 7.2.0.1422 with Tabs setup.
https://github.com/richp582/PrismBug
Please run this sample as is and then click "click me" and notice 2 things.
1.) ViewModels\TabbedPageViewModel.cs Method: InitializeAsync the Debug.WriteLine is called 1 time
2.) Observe that the PageAViewModel is bound and displays "This is Page A" on the Form.
Update All Prism packages to 8.0 (latest, as of now, 8.0.0.1909)
Run the sample again, click the "click me" and observe
1.) ViewModels\TabbedPageViewModel.cs Method: InitializeAsync the Debug.WriteLine is called 3 times
2.) The constructor for PageAViewModel is NOT called and the label is not displayed.
TabbedPageViewModel.InitializeAsync should only be called 1 time as is with 7.2
Page View Models should be instantiated and bound as was with 7.2
TabbedPageViewModel.InitializeAsync is called 3 times
Tab Page View Models are not instantiated and bound to the view
None
I believe this is a xamarin forms issue.
https://github.com/xamarin/Xamarin.Forms/issues/12399
I'm not sure... I'm using the latest Xamarin w/ Prism 7.2 and everything is fine... the only change required to break it is upgrading prism to 8.0
This was due t a change in the way the VML works. Since the VML is now applied automatically by prism instead, it now checks to make sure there is no binding context before applying the VML attribute. Since you are defining your tabs directly in XAML, they will inherit the binding context of the parent tab page (giving the child tabs a binding context), which means the VML is not automatically applied to the tabs anymore.
see https://github.com/PrismLibrary/Prism/blob/master/src/Forms/Prism.Forms/Common/PageUtilities.cs#L286
You need to manually opt-into the VML for the child tabs
Just add this to your PageA and PageB and it will work as expected
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
By the way, we are going to add an additional check against the parent binding context and if it is the same as the view we will automatically apply the VML to fix this scenario.
@brianlagunas that was it, perfect, thanks a lot!! Solved both of my issues!
This is still broken/not working even with AutoWireViewModel set, please refer to sample https://github.com/uwe-e/PrismPages
Actually when I made these changes to my actually app and upgraded to prism 8, I was still having a LOT of regression issues... however I don't have the bandwidth to create another sample at this time and as such we're staying on 7.2 for the time being
I've added new bug with the link to sample project, hopefully will get fixed soon.
Hi - we updated to Prism 8.0.0 - and i currently see the same behaviour. The ViewModel for the Childrens are NOT created - instead all Childrens have the BindingContext set to the Main View - is this the expected behaviour now in 8.0.0? I could workaround it by adding prism:ViewModelLocator.AutowireViewModel="True" to the Childrens - just wonder is this is the expected behaviour now? Could not finde anything in the Release Notes?
thx
Martin
@noxe this is a known issue and has been fixed. However, the fix has not been published to Nuget yet. No timeline on when that will happen
oh - perfect - thank you for the very quick respone Brian!!
Most helpful comment
This was due t a change in the way the VML works. Since the VML is now applied automatically by prism instead, it now checks to make sure there is no binding context before applying the VML attribute. Since you are defining your tabs directly in XAML, they will inherit the binding context of the parent tab page (giving the child tabs a binding context), which means the VML is not automatically applied to the tabs anymore.
see https://github.com/PrismLibrary/Prism/blob/master/src/Forms/Prism.Forms/Common/PageUtilities.cs#L286
You need to manually opt-into the VML for the child tabs
Just add this to your PageA and PageB and it will work as expected