question

sphauck avatar image
0 Votes"
sphauck asked ColeXia-MSFT commented

Xamarin Shell page appearing or navigated to event ?

I may be missing it but when I navigate back to a page from say a detail edit page using Xamarin Shell how do I know I need to refresh the data ? Is there an event somewhere that I can override to use as a "refresh" when the page is being navigated to ? Thanks for any and all help or suggestions !

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ColeXia-MSFT commented

Hello,

Welcome to Microsoft Q&A!

You could refresh the data in OnAppearing method or Shell.Current.Navigated event .

OnAppearing


protected override void OnAppearing()
  {
      base.OnAppearing();

      //refresh the data
  }


Shell.Current.Navigated



public YourPage()
  {
      InitializeComponent();

      Shell.Current.Navigated += (sender,e) => { 
          if(e.Source == ShellNavigationSource.Pop)
          {
                //refresh the data
          }
      };
  }


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I should have mentioned that I have an event that overrides the OnAppearing already like so

78630-image.png

I was looking for something more "automagic" in an MVVM architecture.
I will give your navigated a try, thanks


0 Votes 0 ·
image.png (17.4 KiB)

So I "unaccepted" your answer for one reason ... if I retrieve data whether into an ObservableCollection<Expense> or a List<Expense> in the invoked "InitializeAsync" method hooked up in the code behind as shown above the view renders and contains no data in the list.

The list is bound in the XAML and the binding context is set in the view constructor like so
79241-image.png

I have checked when the InitializeAsync runs and there is data returned but not "bound".

How do I resolve this as to not be what appears to be a "timing" issue ?


0 Votes 0 ·
image.png (29.7 KiB)

Did you viewmodel implement INotifyPropertyChanged ?


0 Votes 0 ·