title: How to add a custom event to a blazor component?
body: <p>I have created a tab control in my blazor server side application, <a href="https://blazor-university.com/templating-components-with-renderfragements/creating-a-tabcontrol/" rel="nofollow noreferrer">based on a tutorial</a>. The control works fine, however I want to be able to tell, when the active page was changed. Therefore I added a event to the code:</p>
  <pre><code>internal void ActivatePage(TabPage page)
  {
      OnTabSelectionChanged();
      ActivePage = page;
  }
  
  public delegate void TabSelectionChangedEventHandler(object source, EventArgs args);
  public event TabSelectionChangedEventHandler TabSelectionChanged;
  
  protected virtual void OnTabSelectionChanged()
  {
      TabSelectionChanged?.Invoke(this, EventArgs.Empty);
  }
  </code></pre>
  <p>Now I want to do the following in my blazor component, which uses the control:</p>
  <pre><code>&lt;TabControl @TabSelectionChanged=&quot;MyFunction&quot;&gt;
      &lt;TabPage Text=&quot;tab #1&quot;&gt;
          &lt;!-- content --&gt;
      &lt;/TabPage&gt;
      &lt;TabPage Text=&quot;tab #2&quot;&gt; 
          &lt;!-- content --&gt;
      &lt;/TabPage&gt;
      &lt;TabPage Text=&quot;tab #3&quot;&gt; 
          &lt;!-- content --&gt;
      &lt;/TabPage&gt;
  &lt;/TabControl&gt;
  </code></pre>
  <p>How would one achieve this?</p>