title: How to get access to an event raised by a custom button in MediaTransportControls?
body: <p>I have a UWP Desktop application that has a MediaPlayerElement with a custom MediaTransportControls. I created two new buttons in the MediaTransportControls to increase and decrease the MediaPlayerElement's PlaybackRate. I've already created procedures that raise the events when buttons are clicked, but I don't know how to access these events on the application's main page, which contains the MediaPlayerElement. How do I do that? Any help is most welcome.</p>
  <p>XAML</p>
  <pre><code>&lt;MediaPlayerElement x:Name=&quot;mediaPlayerElement&quot; 
                                  AutoPlay=&quot;False&quot; 
                                  HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Top&quot;
                                  Margin=&quot;0,0,0,100&quot;
                                  AreTransportControlsEnabled=&quot;True&quot; &gt;
                          &lt;MediaPlayerElement.TransportControls&gt;
                              &lt;local:CustomMediaTransportControls x:Name=&quot;customMTC&quot;
                                               IsSkipBackwardEnabled=&quot;False&quot;
                                               IsSkipBackwardButtonVisible=&quot;False&quot;
                                               IsSkipForwardEnabled=&quot;False&quot;
                                               IsSkipForwardButtonVisible=&quot;False&quot;
                                               IsFastForwardButtonVisible=&quot;True&quot;
                                               IsFastForwardEnabled=&quot;True&quot;
                                               IsFastRewindButtonVisible=&quot;True&quot;
                                               IsFastRewindEnabled=&quot;True&quot; 
                                              IsFullWindowButtonVisible=&quot;False&quot;
                                              IsNextTrackButtonVisible=&quot;False&quot;
                                              IsPreviousTrackButtonVisible=&quot;False&quot;
                                              IsZoomButtonVisible=&quot;False&quot;/&gt;
                          &lt;/MediaPlayerElement.TransportControls&gt;
                      &lt;/MediaPlayerElement&gt;
  
  &lt;!--Custom Buttons--&gt;
                                          &lt;AppBarButton x:Name='CustomPlaybackRateDownButton'
                        Style='{StaticResource AppBarButtonStyle}'
                        MediaTransportControlsHelper.DropoutOrder='18' Visibility=&quot;Visible&quot;&gt;
                                              &lt;AppBarButton.Icon&gt;
                                                  &lt;FontIcon FontFamily=&quot;Segoe MDL2 Assets&quot; Glyph=&quot;&amp;#xE70D;&quot;/&gt;
                                              &lt;/AppBarButton.Icon&gt;
                                          &lt;/AppBarButton&gt;
  
                                          &lt;AppBarButton x:Name='CustomPlaybackRateUpButton'
                        Style='{StaticResource AppBarButtonStyle}'
                        MediaTransportControlsHelper.DropoutOrder='19' Visibility=&quot;Visible&quot;&gt;
                                              &lt;AppBarButton.Icon&gt;
                                                  &lt;FontIcon FontFamily=&quot;Segoe MDL2 Assets&quot; Glyph=&quot;&amp;#xE70E;&quot;/&gt;
                                              &lt;/AppBarButton.Icon&gt;
                                          &lt;/AppBarButton&gt;
  </code></pre>
  <p>Code Behind</p>
  <pre><code>public sealed class CustomMediaTransportControls : MediaTransportControls
  {
      public event EventHandler&lt;EventArgs&gt; PlaybackRateDownClicked;
      public event EventHandler&lt;EventArgs&gt; PlaybackRateUpClicked;
  
      public CustomMediaTransportControls()
      {
          this.DefaultStyleKey = typeof(CustomMediaTransportControls);
      }
  
  
      protected override void OnApplyTemplate()
      {
          // Find the custom button and create an event handler for its Click event.
          var downButton = GetTemplateChild(&quot;CustomPlaybackRateDownButton&quot;) as Button;
          downButton.Click += CustomPlaybackRateDownButton_Click;
  
          var upButton = GetTemplateChild(&quot;CustomPlaybackRateUpButton&quot;) as Button;
          upButton.Click += CustomPlaybackRateUpButton_Click;
  
          base.OnApplyTemplate();
      }
  
  
      private void CustomPlaybackRateDownButton_Click(object sender, RoutedEventArgs e)
      {
          var OnPlaybackRateDownClick = PlaybackRateDownClicked;
  
          if (OnPlaybackRateDownClick != null)
          {
              OnPlaybackRateDownClick(this, EventArgs.Empty);
          }
      }
  
      private void CustomPlaybackRateUpButton_Click(object sender, RoutedEventArgs e)
      {
          var OnPlaybackRateUpClick = PlaybackRateUpClicked;
  
          if (OnPlaybackRateUpClick != null)
          {
              OnPlaybackRateUpClick(this, EventArgs.Empty);
          }
      }
  
  
  }
  </code></pre>