Home » Android » android – How to refresh an object in C# after updating on another page and returning with popasync()-Exceptionshub

android – How to refresh an object in C# after updating on another page and returning with popasync()-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

I have a PlayerDetailPage.xmal that shows the detail of a player object.

<!-- Row 0 Col 0-1 -->
<Image Grid.ColumnSpan="2"
  Source="{Binding PlayerImage}"
  HeightRequest="60"
  WidthRequest="60" />
<!-- Row 0 Col 2-4 -->
<Label Grid.Column="2" 
  Text="{Binding PlayerName}"
  FontSize="18"
  FontAttributes="Bold" />

<!-- Row 1 Col 0 -->
<Label Grid.Row="1"
  Text="Wins: " />
<!-- Row 1 Col 1 -->
<Label Grid.Row="1"
  Grid.Column="1"
  Text="{Binding TotalMatchesWon}" />
<!-- Row 1 Col 2 -->
<Label Grid.Row="1"
  Grid.Column="2"
  Text="Losses: " />
<!-- Row 1 Col 3-->
<Label Grid.Row="1"
  Grid.Column="3"
  Text="{Binding TotalMatchesLost}" />

<!-- Row 2 Col 0-->
<Label Grid.Row="2"
  Grid.ColumnSpan="4"
  Text="Matches Played"
  FontAttributes="Bold" />

Selecting the Edit button launches a PlayerEntryPage that allows the user to update the player: (PlayerDetailPage.xmal.cs)

async void OnEditPlayerButtonClicked(object send, EventArgs e)
    {
        Player myPlayer = this.BindingContext as Player;

        await Navigation.PushAsync(new RosterEntryPage
        {
            BindingContext = myPlayer
        });
    }

When I save the updated record and popasync() back to the detail page, it does not show the details of the updated record. (RosterEntryPage.xmal.cs):

async void OnRosterEntrySaveButtonClicked(object sender, EventArgs e)
    {
        var player = (Player)BindingContext;

        player.JoinDate = DateTime.UtcNow;
        await App.Database.SavePlayerAsync(player);

        await Navigation.PopAsync();
    }

If I drop back one level from the detail page to the general page that has a list of players, the list shows the updated information. And if I select the player the detail page will show the updated information.

How do I refresh the Detail page when saving the updates?

How to&Answers: