How can I refresh a page?

Greetings, I am starting in xamarin forms and I have the following problem
I have two pages page1 and page2 of type NavigationPage, on page1 I show a series of data and information to the user and I can go with a button to page2 which is a kind of form that the user can fill out but when filling in some fields on page1 they should be updated the doubt is the following how can I refresh the page1 from page2? , on page1 I have a function that refreshes the fields that I want to update by printing these changes on the screen. Is it possible to call that function from page2? I try to do the static function but I get an error in the elements of the xaml on page1 that I want to change
Another question I have is why, if I surf, do I have a lot of navigation from page1 to page2 and vice versa does the app end?
to go from page1 to page2 use:
await ((NavigationPage) this.Parent) .PushAsync (new Page2 ());

and to go from page2 to page1 use:
await ((NavigationPage) this.Parent) .PushAsync (new Page1 ());

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Stop building.

    Clearly you haven't done any of the tutorials on foundation concepts such as MVVM.

    Data doesn't flow from page to page. It flows from ViewModel to VIewModel.
    If you need page 1 and 2 to have some data in common they just need to look at the same ViewModel.

    I'm going to suggest something you won't want to hear.
    Learn first. Develop second. How can you build a program if you haven't learned the foundation concepts like MVVM or MessagingCenter?

    So many noobies take this "no time to study, I have to bang this out now and learn as I go" direction - and it rarely works out well.

    Had you taken the time to do Xamarin University or even a short blog course, you would have already learned the basics like designing UI, binding, MVVM patterns, Messaging between your pages and ViewModels - all the beginner basics you need to get started.

    Stop working on this project for at least a couple weeks to a month. Just work on learning. WORK some tutorials from start to end. Build the sample apps the authors are walking you through. Then dissect those apps to gain real comprehension of all the relationships and moving parts. Then take that new understanding and start version two of this app from scratch.

    Free textbook
    https://blogs.msdn.microsoft.com/microsoft_press/2016/03/31/free-ebook-creating-mobile-apps-with-xamarin-forms/

    Xamarin University
    https://university.xamarin.com/

    Xamarin University has dozens of tutorial classes on YouTube if you use their search feature.

    And of course there are dozens of Xamarin bloggers out there.
    http://redpillxamarin.com/2018/03/12/2018-101-vs2017-new-solution/

  • amirvenusamirvenus USMember ✭✭✭

    Use DataBinding and implement INotifyPropertyChanged interface so it can notify the changes and the data will be automatically refreshed on all pages bound to that Binding!

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai
    edited January 14

    when filling in some fields on page1 they should be updated the doubt is the following

    As ClintStLaurent and amirvenus pointed out, MVVM & Data Binding is what you are looking for. Here are some tutorials about this in Xamarin

    if I surf, do I have a lot of navigation from page1 to page2 and vice versa does the app end?

    Please elaborate a bit more. I don't get what you mean. Also, I think you could find the answer in this documentation: Xamarin.Forms -- Hierarchical Navigation

Sign In or Register to comment.