I've created a platform specific page using PageRenderer and I need to pass data back from this page when a button is clicked.
I've looked at using the DependancyService but all I can find is to call a method in the platform project from the PCL, I need to do the opposite, is this possible? Or would I be better advised to look at using traditional Event - EventHandler, is this the preferred approach in Xamarin or is there a better way to handle this in Xamarim.Forms?
The data is need to pass back is an object;
public class CallAcknowledged
{
public string CustomerName { get; set; }
public DateTime CallAcknowledged { get; set; }
public byte[] Signature { get; set; }
}
I've managed to find the answer in this post from @AlessandroCaliaro on the Xamarin Forum https://forums.xamarin.com/discussion/70235/xamarin-forms-messagingcenter-between-two-differents-pages-projects
I needed to do use the PCLProjectName.App as the source of the message and it works a dream.
Sender
MessagingCenter.Send<MyMobileApp.App, string>((MyMobileApp.App)Xamarin.Forms.Application.Current, "Acknowledged", fullNameValue);
Subscriber
MessagingCenter.Subscribe<MyMobileApp.App, string>((App)Application.Current, "Acknowledged", (sender, arg) =>
{
Debug.WriteLine("Full Name : " + arg);
});
Thanks to @MarkusMichel for pointing me in the right direction
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.