c#-如何访问MediaTransportControl中的自定义按钮引发的事件?
发布时间:2022-03-01 13:39:24 508
相关标签: # flask
我有一个UWP桌面应用程序,它有一个带有自定义MediaTransportControl的MediaPlayerElement。我在MediaTransportControls中创建了两个新按钮,以增加和减少MediaPlayerElement的播放速率。我已经创建了在单击按钮时引发事件的过程,但我不知道如何访问应用程序主页上的这些事件,其中包含MediaPlayerElement。我该怎么做?欢迎任何帮助。
XAML
<MediaPlayerElement x:Name="mediaPlayerElement"
AutoPlay="False"
HorizontalAlignment="Center" VerticalAlignment="Top"
Margin="0,0,0,100"
AreTransportControlsEnabled="True" >
<MediaPlayerElement.TransportControls>
<local:CustomMediaTransportControls x:Name="customMTC"
IsSkipBackwardEnabled="False"
IsSkipBackwardButtonVisible="False"
IsSkipForwardEnabled="False"
IsSkipForwardButtonVisible="False"
IsFastForwardButtonVisible="True"
IsFastForwardEnabled="True"
IsFastRewindButtonVisible="True"
IsFastRewindEnabled="True"
IsFullWindowButtonVisible="False"
IsNextTrackButtonVisible="False"
IsPreviousTrackButtonVisible="False"
IsZoomButtonVisible="False"/>
</MediaPlayerElement.TransportControls>
</MediaPlayerElement>
<!--Custom Buttons-->
<AppBarButton x:Name='CustomPlaybackRateDownButton'
Style='{StaticResource AppBarButtonStyle}'
MediaTransportControlsHelper.DropoutOrder='18' Visibility="Visible">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton x:Name='CustomPlaybackRateUpButton'
Style='{StaticResource AppBarButtonStyle}'
MediaTransportControlsHelper.DropoutOrder='19' Visibility="Visible">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</AppBarButton.Icon>
</AppBarButton>
代码隐藏
public sealed class CustomMediaTransportControls : MediaTransportControls
{
public event EventHandler PlaybackRateDownClicked;
public event EventHandler 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("CustomPlaybackRateDownButton") as Button;
downButton.Click += CustomPlaybackRateDownButton_Click;
var upButton = GetTemplateChild("CustomPlaybackRateUpButton") 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);
}
}
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报