Hi rotorgames ,
How to refresh the Parent Page from Pop up page save&close?
In our scenario, we are editing particular (List Collection) item from Listview using pop up screen with date,picker and entry values.
We need to update/Refresh the List Collection of List view alone in Parent screen.
How to acheive this with pop up implementation.
Hi friend.
You can use the event or callback delegates.
For example:
// PopupPage
// Event
public event EventHandler<IList> CallbackEvent;
// or Callback
public delegate void CallbackDelegate(IList list);
public CallbackDelegate CallbackMethod {get;set;}
private void InvoceCallback()
{
CallbackEvent?.Invoce(this, youList);
// or
CallbackMethod?.Invoce(youList);
}
// You Forms Page
var popupPage = new YouPopupPage();
// Event
popupPage.CallbackEvent += OnCallback;
// Or
popupPage.CallbackMethod = OnCallback;
This basic concepts when working with C #, and have nothing to do with my library. I advise you to learn C # more closely. Thank you.
Hi rotorgames,
Thanks for your valuable suggestion. We will check the above approach and as well as other suitable approach for our scenario.
Thank you so much for your support.
Hi @rotorgames,
I couldnt achieve this. do you have a full sample maybe? I am trying to build a custom ActionSheet using your popup. but I am not able to get the value returned. is there a way to await for a response like below
string result = await CoreMethods.DisplayActionSheet("Complete?", cancel: CancelText, destruction: null, buttons: parameters.ToArray());
I have the same issue
My popup is a separate page and I am opening it this way from MerchantCategoryPage:
await Navigation.PushPopupAsync(new ZeeraPopupNewMerchantCategory());
When closing the popup using the Button placed on the popup, how can I run:
GetMerchantCategory();
which is located in the MerchantCategoryPage (the parent)?
Thanks
@jrahma You should create callback event. See the example that I created.
I tried below but nothing is heppening.. I expect when closing the popup using PopAllPopupAsync to show the alert (but not when background click / cancel)
public void OnPopupSpecialPushNotificationsCallback(object sender, object e)
{
DisplayAlert("Done", "Popup Closed using PopAllPopupAsync", "OK");
}
async void ImageStoryPushNotifications_Tapped(object sender, System.EventArgs e)
{
var popupStory = new PopupSpecialPushNotifications(story_guid);
popupStory.CallbackEvent += OnPopupSpecialPushNotificationsCallback;
await Navigation.PushPopupAsync(popupStory);
}
In my PopupPage:
public event EventHandler<IList> CallbackEvent;
@jrahma You must invoke CallbackEvent yourself
is there any example there please?
@jrahma
// PopupPage
// Event
public event EventHandler<object> CallbackEvent;
private void InvoceCallback()
{
CallbackEvent?.Invoce(this, anyObjectForResult);
}
// You Forms Page
var popupPage = new YouPopupPage();
// Event
popupPage.CallbackEvent += OnCallback;
I have tried below:
Popup Page:
public delegate void CallbackDelegate(IList list);
public CallbackDelegate CallbackMethod { get; set; }
private void InvokeCallback()
{
CallbackMethod?.Invoke(youList);
}
In the my Form:
var popupUnits = new PopupUnits();
popupUnits.CallbackMethod = OnPopupUnitsCallback;
await Navigation.PushPopupAsync(popupUnits);
public void OnPopupUnitsCallback(object sender, System.EventArgs e)
{
App.Current.MainPage.DisplayAlert("Closed", "Successfully Added to your favorite.", "Ok");
}
but I have below problems:
@jrahma I have updated my previous example. It is easy. Just use events if you use just xamarin forms or look for library for your mvvm framework or create your implementation for it. I support only xamarin forms right now.
Hi, I would like to elaborate over the solution.
I have worked very little with events and such before, so I went through some troubles to finally get to solution to my problem.
All in all I just needed to update a list when the popup closes.
The thing is: as I was using MVVM, all the directions and examples were a little bit confusing for me hehe.
But here we go.
Inside the view model where you open the popup:
private void OpenAddIncomePopup()
{
var popupPage = new AddIncomePopup();
// event callback
popupPage.CallbackEvent += (object sender, object e) => CallbackMethod(); // the method where you do whatever you want to after the popup is closed
PopupNavigation.Instance.PushAsync(popupPage);
}
Inside popup page (not inside view model, but inside the very class that implements "PopupPage" class):
// event callback
public event EventHandler<object> CallbackEvent;
protected override void OnDisappearing() => CallbackEvent?.Invoke(this, EventArgs.Empty);
And voil脿 - just by overriding the OnDisappearing method this can be very easy :)
Thanks a lot for the lib, @rotorgames. It's helping me a lot.
@jrahma I have updated my previous example. It is easy. Just use events if you use just xamarin forms or look for library for your mvvm framework or create your implementation for it. I support only xamarin forms right now.
i couldnt do anything. please can u help me?
I managed to do it with xamarin message center.
But i want this way to improve myself.
You wrote CallbackEvent?.Invoce is it Invoke ?
I m new to c# . could u help me making a very simple project ( xamarin forms)? thank u
@fkbeys I moved to @syncfusion much powerful and full functions
@fkbeys I moved to @syncfusion much powerful and full functions
Why in the world do you write that? Just because you couldn't achieve. you suggest a tool that you can plug and use it. I also use it Syncfusion in many of my projects but it is not more powerful. It has many bugs and you don't have a power of control as you don't have the source code. If you a have bug, you can just report and wait them to fix it. But if you are good developer, you can clone source code of this project and debug yourself , fix yourself. This is the power in your hand and i don't believe that you have due to say that Syncfusion is more powerful. This is a disrespect to the Source code owners hard valuable work.
@EmilAlipiev it's not disrespect. I was using this tool for many years and might use it for some future projects. @syncfusion is also a great option. Developer needs to decide which one is best for the project.
So better you can say that it fit better you. For me their popup wasnt a good option. It is integrated on the actual contentpage and occupies more memory usage as Rg popup which runs on standalone thread and you can dispose it once you are finished your work and return back to your original page.
@fkbeys I moved to @syncfusion much powerful and full functions
thank u sir. i will try it. i already solved how to do this also. thank u.
Most helpful comment
Hi, I would like to elaborate over the solution.
I have worked very little with events and such before, so I went through some troubles to finally get to solution to my problem.
All in all I just needed to update a list when the popup closes.
The thing is: as I was using MVVM, all the directions and examples were a little bit confusing for me hehe.
But here we go.
Inside the view model where you open the popup:
Inside popup page (not inside view model, but inside the very class that implements "PopupPage" class):
And voil脿 - just by overriding the OnDisappearing method this can be very easy :)
Thanks a lot for the lib, @rotorgames. It's helping me a lot.