Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to use MessagingCenter to pass a message from an Android project to the PCL project?

$
0
0

I'm struggling to pass a message from my Android project to my PCL project using MessagingCenter.
In my PCL project, I have a ContentPage called "AboutPage", while on the Android project I have a ScaleImageView class that inherits from ImageView.

When an event occurs on ScaleImageView, I want to pass a message to the AboutPage. Here's what I have so far...

On ScaleImageView.cs

var mp = App.Current.MainPage;
MessagingCenter.Send<AboutPage, string>((AboutPage)mp, "PageSwipe", "NextPage");

On AboutPage

MessagingCenter.Subscribe<AboutPage, string>(this, "PageSwipe", (sender, arg) =>
            {
                DisplayAlert("Message Received", "arg=" + arg, "OK");
            });

But this is not working, I get an error when the MessagingCenter code executes, which I wrote based on this post...
https://forums.xamarin.com/discussion/26681/need-to-get-message-back-to-forms-pcl-from-android-prj


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>