Replies: 3 comments
-
@haavamoa Interesting question. The current behavior is intentional, although what you need in your App has made me think about it in ways that we could cover both cases (have a new view model in between the pages or reuse it). |
Beta Was this translation helpful? Give feedback.
-
Interesting indeed. Not entirely sure if you need more information from me or not. Our solution was to keep one view model for each page, but to have a viewmodel globally in the first page that gets sent to the second viewmodel when the second page is created. That way we have a sort of scoped singleton that has pre-loaded data and can be used by the pull to refresh to get data. |
Beta Was this translation helpful? Give feedback.
-
We use MVVMCross, where ViewModels are not re-created, so every time we switch views, we get "one extra" refresh when Pull-To-Refresh is called on the RefreshView. It does not look possible to prevent this, VMs lifescycle is handled by MVVMCross. |
Beta Was this translation helpful? Give feedback.
-
Description
Hi, and thank you for the awesome work with
RefreshView
. This issue is more of a question regardingRefreshView
that keeps it's bindings when you have a page that gets navigated to.Here is a project that has:
MainPage
andSecondPage
MainPage
has a button that navigates toSecondPage
RefreshView
with aScrollView
, which means that I can pull to refresh.SecondPage
get's newed up and navigated to when you click the button inMainPage
.SecondPage
binding context get's set to a global view model, which means that the binding context instance lives even if the page get's navigated out of.RefreshCommand
and aIsRefreshing
.The first time I navigate to
SecondPage
and pull to refresh the command gets run. Great.When I navigate back and forth and do the same thing, the commands gets run twice.
When I navigate back and forth and do the same thing, the commands gets run three times.
This keeps going on.
Is this an intentional behavior?
We are doing this in an production app because we want the
MainPage
to bind to properties of the binding context of theSecondPage
. We also want to pre-load the second pages binding context data when theMainPage
loads. So thats why that binding context is shared and not newed up with every page.I respect it if it is intentional, I just want to hear from the Xamarin.Forms team if it is so. If it is, I can change my architecture to bypass the problem.
Expected Behavior
The
RefreshView
's command to run once every time.Actual Behavior
The
RefreshView
's command to run's x amount of times I've navigated to the page.Basic Information
Reproduction Link
https://github.com/haavamoa/GithubIssues/tree/master/src/RefreshViewSharedBindingContext
Workaround
Change the architecture to always new up a view model and have a new viewmodel in between the pages.
Beta Was this translation helpful? Give feedback.
All reactions