I have a simple MediaPlayerElement defined in xaml and I would like to run some c# code when a user hits the play button on the transport controls but I can't find an event handle exposed to XAML to do that. Can it be done? ...
<MediaPlayerElement
Visibility="Visible"
x:Name="mp"
Source="C:/Users/Brian/Videos/happy.mp4"
AutoPlay="False"
AreTransportControlsEnabled="True"
Stretch="UniformToFill"
>
</MediaPlayerElement>
You need to use the MediaPlayer inside the MediaPlayerElement and subscribe to its
CurrentStateChanged:and
or if you need the
Clickevent of the play button, which is anAppBarButtonnamed PlayPauseButton:then
NOTE:
FindDescendantscomes from the CommunityToolkit.WinUI.Extensions NuGet package.