title: Custom Events in Xamarin Page c#
body: <p>I currently am facing the following issue:</p>
  
  <p>I am trying to fire an event when a user entered valid credentials so that I can switch page and so on.</p>
  
  <p>The Issue is I am unable to hook into the event for some reason (altho I'm pretty sure it will be something stupid).</p>
  
  <p>The Class firing the event:</p>
  
  <pre><code>namespace B2B
  {
  
      public partial class LoginPage : ContentPage
      {
          public event EventHandler OnAuthenticated;
  
          public LoginPage ()
          {
              InitializeComponent ();
          }
  
          void onLogInClicked (object sender, EventArgs e)
          {
              loginActivity.IsRunning = true;
  
              errorLabel.Text = "";
  
              RestClient client = new RestClient ("http://url.be/api/");
  
              var request = new RestRequest ("api/login_check",  Method.POST);
              request.AddParameter("_username", usernameText.Text);
              request.AddParameter("_password", passwordText.Text);
  
              client.ExecuteAsync&lt;Account&gt;(request, response =&gt; {
  
                  Device.BeginInvokeOnMainThread ( () =&gt; {
                      loginActivity.IsRunning = false;
  
                      if(response.StatusCode == HttpStatusCode.OK)
                      {
                          if(OnAuthenticated != null)
                          {
                              OnAuthenticated(this, new EventArgs());
                          }
                      }
                      else if(response.StatusCode == HttpStatusCode.Unauthorized)
                      {
                          errorLabel.Text = "Invalid Credentials";
                      }
                  });
  
              });
  
          }
      }
  }
  </code></pre>
  
  <p>And in the 'main class'</p>
  
  <pre><code>namespace B2B
  {
      public class App : Application
      {
          public App ()
          {
              // The root page of your application
              MainPage = new LoginPage();
  
              MainPage.OnAuthenticated += new EventHandler (Authenticated);
  
          }
  
          static void Authenticated(object source, EventArgs e) {
              Console.WriteLine("Authed");
          }
      }
  }
  </code></pre>
  
  <p>When I try to build the application I get:</p>
  
  <p><strong>Type 'Xamarin.Forms.Page' does not containt a definition for 'OnAuthenticated' and no extension method OnAuthenticated</strong></p>
  
  <p>I've tried adding a delegate inside the LoginPage class, outside of it but it doesn't help.</p>
  
  <p>Could anyone be so kind to point me out what <em>stupid</em> mistake I am making ?</p>