I'm Using Rg.Plugins.Popup, and "Popping" a ListView Page with a bunch of clients in the listview and i want to return a cliente selected back to the page that a was before, I try something like this...
ClientsListView.ItemTapped += async (sender, args) => { ClientsListView.SelectedItem = null; var item = args.Item as Clientes; if (item == null) return; await Navigation.PopPopupAsync(item); };
But obviously this didn't work...
Some help would be great...
I think you can pass the "father" ViewModel to the "Popup", update it and when the Popup is closed, you should have your "father" ViewModel updated.
Otherwise, MessaggingCenter is a good solution
Answers
Don't worry about sending the event back.
The popup still exists in memory after its closed, as long as your caller keeps it in scope.
So try this logic...
No different that when you have an
OpenFileDialog
from Windows. You open the dialog. The user selects a file. Closes the dialog. Then you check theFilePath
property of the dialog.Same pattern here.
Can you send a example, i really never do it...
I'm not writing your code for you. Put in some time, energy, thought, trial & error at it then post your code and any errors you get. I'm happy to help you - To become a better coder and that is only done through practice and working to stretch your skillset forward. Skill and learning aren't accomplished through copy/paste.
I think you can pass the "father" ViewModel to the "Popup", update it and when the Popup is closed, you should have your "father" ViewModel updated.
Otherwise, MessaggingCenter is a good solution
I try this but the ViewModel didn't update the previous page...
Can i send a ListView Selected item through messagingcenter??
What page would be the Subscribe, the Main Page or the Popup Page?
If your using Prism you can use this pluggin which allows you to hook popups into the navigation service and then you can just pass back parameters like you normally would.
https://github.com/dansiegel/Prism.Plugin.Popups
Sorry for taking so long to respond, i had a job that needed full Atention...
I end up doing this job throught MessagingCenter Sending the SelectedItem of the ListView on the PopUp back to the page i was early and it work's perfectily, Many Thanks...
@NMackay
which navigation method do i need to override on my main page so that i can work with the navigation parameters returned from the popup page using
await _navigationService.PopupGoBackAsync ...........
doesn't seem to be firing when i use this approach
thanks in advance,
jas
It should work fine using version 1.1.0 of Prism.Plugin.Popup, I'm using Unity, Prism 6.3 & Forms 2.3.5-pre6 at present.
In the popup viewmodel:
And in the viewmodel of the original calling page
my popup page has
while my calling page that does not fire is
ill try on a clean app this evening and see how i get on
I'd have to peek about in the source and ask Dan but OnNavigatedFrom may not fire,we don't use that approach, we pass the parameters when we push the Popup and use OnNavigatedTo when passing back in the original calling VM, for example, OnNavigatingTo won't fire. I'd stick to using OnNavigatedTo for Popups & Prism.
sorry, OnNavigatedTo , i was playing around to see which would fire.
If you don't get it working, knock up a little repo project and I'll take a look tomorrow.
@NMackay
thanks for the offer.
ive made a copy of my app and stripped it down and OnNavigatedTo does indeed fire so ill spend some time over the weekend looking over the full app again.
thanks again
Here's the solution you're looking for
https://theconfuzedsourcecode.wordpress.com/2017/07/26/an-await-able-transparent-custom-popup-input-dialog-in-xamarin-forms/
You could achieve this requirement even without the MVVM support, as shown in the article.
Here's the exact ListView input selection implementation you're looking for:
https://github.com/UdaraAlwis/Xamarin-Playground/blob/master/XFCustomInputAlertDialog/XFCustomInputAlertDialog/XFCustomInputAlertDialog/InputViews/SelectableInputView.xaml.cs
Cheers!
It's in the OnNavigatedTo event
` if (parameters.TryGetValue("SelectedItem", out MySelectedObjectType selectedItem))
{
That keeps it in the MVVM pattern.
Hello Could you share a sample code of your final solution of sending the SelectedItem back? I am facing the same issue and just cant image how to do it. Thank you.