Maui View add events

Lloyd Sheen 1,391 Reputation points

I have now read about 50 posts "about" this and nothing I have read works.

Read MS docs and nothing.

What I am trying to do should be simple. I have a ContentView control and I want to add events to it. I can find no information on how to do this.

Can anyone link to a post that shows how to define it / raise it / and consume it.


A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,977 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Josh Pierce 1 Reputation point

    I normally use MessagingCenter for that purpose. You can Raise a message using

    MessagingCenter.Send<VIEWNAME, DATATYPE>(this, "MESSAGE", DATATOSEND);

    Then you can subscribe to those messages from whatever class you need using

    MessagingCenter.Subscribe<FROMVIEW, Incoming Data Type>(this,"MESSAGE", async (sender, arg) =>

  2. John Rutterford 5 Reputation points

    You can standard Events in a ContentView.

    Basic sample usage:

    public partial class PickList : ContentView
        public event EventHandler<EventArgs> PickListChanged;

    Then in your code:

    private void Gesture_Tap(object sender, TappedEventArgs e)

    Then in your page XAML:

    <mycontrols:PickList PickListChanged="Picker_PickListChanged"></mycontrols:PickList>
    0 comments No comments