lundi 12 juin 2017

Subscribe to DisplayAlert in Xamarin.Forms

I'd like to get notified whenever DisplayAlert is called somewhere in my app. The Xamarin.Forms source code suggests to use the MessagingCenter, since it is using it to send a message within DisplayAlert():

MessagingCenter.Send(this, AlertSignalName, args);

But I haven't been able to receive anything, yet. This is one of the lines I tried so far:

MessagingCenter.Subscribe<Page>(this, Page.AlertSignalName, arg => {
    Console.WriteLine("Message received: " + arg);
});

Is this the right direction? Or do you have an alternative solution? I'd even consider some hacky reflection-based approach, since I need it for testing purposes only.

Aucun commentaire:

Enregistrer un commentaire