Hello,
Welcome to our Microsoft Q&A platform!
When I run for the first time I can see all my notebooks, but if I select a note and come back to the MainPage and insert a new notebook, I cannot see it. It looks like it doesn't update the >observable
This issue is related to observable do not update when you close the popup page. When popup page closed, your App.services.ReadAsync(App.Notebooks);
need to be called.
So I add a event in the NotebookPopUp
background code. If the pop up page is closed, invoke this event in the MainPage's viewmodel. If you want to know more details about Raise event, please see : How to: Raise and Consume Events
public partial class NotebookPopUp : PopupPage {
public NotebookPopUp() {
InitializeComponent();
}
protected override bool OnBackButtonPressed() {
return true;
}
//add this event
public event EventHandler PopPageClosed;
// If the pop up page is closed, invoke this event in the MainPage's viewmodel
protected override void OnDisappearing()
{
PopPageClosed.Invoke(this, EventArgs.Empty);
base.OnDisappearing();
}
protected override bool OnBackgroundClicked() {
return false;
}
}
Then open your MainPage's viewmodel MainPageModel.cs
. Find AnimateButtonCommand
method. Register the event by notebookPopUp.PopPageClosed += NotebookPopUp_PopPageClosed;
And add App.services.ReadAsync(App.Notebooks);
code to NotebookPopUp_PopPageClosed
method.
private async void AnimateButtonCommand(Frame obj) {
await obj.ScaleTo(0.8, 50, Easing.Linear);
NotebookPopUp notebookPopUp= new NotebookPopUp();
//register this event
notebookPopUp.PopPageClosed += NotebookPopUp_PopPageClosed;
await PopupNavigation.Instance.PushAsync(notebookPopUp);
}
//if the PopUp page closed, get the data again
private void NotebookPopUp_PopPageClosed(object sender, System.EventArgs e)
{
App.services.ReadAsync(App.Notebooks);
}
Now, If you pop up page is closed. You can get the data again. Mainpage could run normally.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.