AutowireViewModel is not working as expected in migrated MAUI app #3258
Replies: 4 comments 5 replies
-
and here i have the watches ar runtime... I spent time to find a solution but I didn't find the cause... |
Beta Was this translation helpful? Give feedback.
-
The behavior of the ViewModelLocator has changed from the Xamarin version. You are most likely checking the value too soon since the VM is not set during construction of the View but rather after. This means the CTOR is too early in the lifecycle. One thing you could try is to set the ViewModelLocator to |
Beta Was this translation helpful? Give feedback.
-
Hi, I am back again, sorry for the late reply but I needed to do crazy test to check what is happening. So now I put the autoowire to Force and the private MyViewModel ViewModel => (MyViewModel)BindingContext; But now I have a different error: page to remove must be containd on this Navigation Page.. (see picture) I searched for the error and I met this #3153 Cheking my code I have ( I think...) all correclty set... I mean, the registration of the navigation: What I am doing wrong? thank you very much |
Beta Was this translation helpful? Give feedback.
-
Hello! I read all the documentation about MAUI, I saw all you video on migrating the app, and how to work with Prism correctly, we checked out the Prism MAUI samples,... but no way to solve the error we have.... So, please, can you give a little help to me? Tell me if we are doing well? Here is the logic we process: The app starts with a: in the MauiProgram.cs file correctly done from the .createWindow method... PD: we read about OnAppStart but no way to get available in code ... https://prismlibrary.github.io/docs/maui/appbuilder.html#onappstart SpashScreen shows correctly telling that we are connecting to the server to get & check same data..... the busy cursor in looping in the screen.... so ok til here.... SpashScreen has a SpashScreenViewModel , and in the CTOR we call a method that, after some checks calls a: ViewA is a flyoutpage that has a ViewAViewModel where in the CTOR we have another navigation to: await _navigation.NavigateAsync("NavigationPage/ViewB"); and here we receive the error of "page to remove must be contained on this navigation page" error.... Note that the only visible page we see in the simulator is the first on SpashScreen, no more page is displayed .... If we call the ViewC without the NavigationPage we don't have any error but the viewC is not showing... the SpashScreen is still visible.... Note that we have only the Prism.DryIoc.Maui package installed. Can you give a little help or advise? Angelo Lazzarimobile: +34 683 137 087mail: [email protected] Verify the correspondence of the addressee; otherwise, notify that to the sender and, conscious of the responsibility for the undue use, destroy the message and its copies. |
Beta Was this translation helpful? Give feedback.
-
Hello, in our old xamarin app we were using the AutowireViewModel=true and now we put the new AutowireViewModel=Automatic property and we left all the rest of the MVVM code like it was.
As you see in the image we set the internal viewmodel variable to the "BindingContext as ..." clause but the problem we have is that once the line is executed the variable is still null.
How can we check that the AutowireViewModel met the correct viewmodel?
Thank you very much!
Beta Was this translation helpful? Give feedback.
All reactions