-
-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ViewModel closing when navigate to new page #1238
Comments
@alexfdezsauco care to join the conversation? You wrote this part. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is a critical bug in Xamarin.Android due to the fact that Page.OnAppearing is called every time the page appears on the phone screen: this may be caused by navigation or by the OS when the app/phone comes out of sleep. |
We definitely want to fix this, but might need a bit of help here, interested? |
I fix this bug in my project by create my own ContentPage with needed behaviour of _userControlLogic |
@okunevdm did you use the UserControlLogic.CloseViewModelOnUnloaded property or came up with another solution? |
I solved this by overriding the OnParentSet method and firing Loaded and Unloaded events depending on whether the Parent is null. |
By the way, we still want to know when the view appears or disappears in associated view model. Any thoughts? Can we extend ViewModelBase with OnAppearing and OnDisappearing methods? |
Why would you want Appearing / Disappearing methods, aren't they equal to Loaded/ Unloaded? In that case, you can (should) implement this in the iView implementation so Catel can deal with this. |
With this they won't longer be equal. Unloaded will be fired when our page leaves the navigation stack. |
I'll prepare sample to show this behavior. |
this is my ContentPage class
` |
for hardware back button in android i override in MainActivity |
Probably I'm blind, but there is only one difference: CustomBackButtonAction. I do not see how this changes the current behavior. |
Please take a look at my sample. |
CustomBackButtonAction uses in concrete instance of contentPage:
` |
now i can not use ViewModel for control of Navigation behavior because of issue https://github.com/Catel/Catel/issues/1252 - i can not show message with buttons yes/no, but DisplayAlert works fine. |
Thus you prevent navigation. We should make it work out of the box, but initial issue is "After navigate to new page previous ViewModel is closing". How did you fix it? |
default CustomBackButtonAction is
|
But if you navigate forward, your view model will still be closed and then recreated. |
oh, yes of course.. )) I forgot that I really used CloseViewModelOnUnloaded and when copy paste code of ContentPage i cut it... sorry.
|
Now it makes sense! |
why? i use NavigationPage/NavigationService and it work fine. |
Maybe we can do type forwarding in https://docs.microsoft.com/en-us/dotnet/framework/app-domains/type-forwarding-in-the-common-language-runtime, but I don't want to lose Windows Phone (windows 10 mobile) support on UAP (use this myself) so updating to the min version of UAP that implements .net standard is not an option. |
Now I think of it, this might be caused because Catel.Core doesn't explicitly use the .net standard 2.0 implementation, but the platform-specific one (that is also included there). Maybe we can force it to use the .net standard one instead. |
Can we support two versions of UAP? Since the Xamarin.Forms common library implements .NETStandard, we can't use the old version of UAP here anyway. |
AFAIK, XF 3+ doesn't support WM10. Thus, we can only support it as a non-XF library |
The issue here is Catel.Core, that supports any platform (and the UWP version picks the UAP, not the .net standard implementation). |
I understood that. I propose to target Catel.Core to uap10.0 (will use local types) and uap10.0.16299 (will use .NETStandard2.0 types). That should solve the problem, isn't it? |
Might work, let me try that. |
Just pushed the first bits, need to leave now, but will try to build it on the build server. |
It works! |
Awesome, thanks for pointing me in the right direction, it was a brilliant idea. You got sufficient stuff working to complete this ticket? |
At first glance, yes. I still need to set up the environment for iOS. I will try to finish ticket at this weekend. |
Do you mind if we put this ticket for 5.11? Then we can close the beta and release 5.10 early next week. |
Yes, let's put it for 5.11. |
@GreenKn1ght any updates? |
Since we removed support for all frameworks exception .NET 6 (WPF) for 6.0, I am closing this issue. |
Catel.MVVM.Xamarin.Forms
After navigate to new page previous ViewModel is closing. And when press back button and return to first page viewmodel for this page create new instance.
is catel:ContentPage contains property like CloseViewModelOnUnloaded?
Expected behaviour
when NavigateForward ViewModel continues to work on background.
when NavigateBack ViewModel closing.
Actual behaviour
ViewModel closing when NavigateForward
The text was updated successfully, but these errors were encountered: