title: Custom event in Xamarin.Forms
body: <p>I was trying to add a custom event to my custom control in Xamarin.Forms. Please take a look at the code below:</p>
  
  <pre><code>public delegate void ImageSelectedHandler(object sender, EventArgs e);
  public static event ImageSelectedHandler OnImageSelected;
  
  private void OnImageBtnTapped(object sender, EventArgs e)
  {
     if (OnImageSelected != null) 
     {
          OnImageSelected(sender,e);
     }
  }
  </code></pre>
  
  <p>In the page which is using the control:</p>
  
  <pre><code>SelectMultipleBasePage&lt;ListItems&gt;.OnImageSelected += ListPage_OnImageSelected;
  
  void ListPage_OnImageSelected(object sender, EventArgs e)
  {
    //code here
  }
  </code></pre>
  
  <p>I could access the event by using the above code. But I would like to use the control on different pages. On different pages different <code>OnImageSelected</code> even will behave differently. And hence I would like to have something like this:</p>
  
  <pre><code>SelectMultipleBasePage&lt;ListItems&gt; multiPage = new SelectMultipleBasePage&lt;ListItems&gt;(items);
  multiPage.OnImageSelected += ListPage_OnImageSelected;
  </code></pre>
  
  <p>But when I do that I get error:</p>
  
  <blockquote>
    <p>Cannot be accessed with an instance reference; qualify it with a type name instead</p>
  </blockquote>
  
  <p>What am I doing wrong in accessing the event?</p>