向标准传输控件添加元素

Add elements to the standard transport control

我想将 selector 添加到 windows 通用应用程序的标准传输控制中,这样我就可以 select 视频质量。

我尝试修改定义了标准控件的xaml,但该控件没有受到影响,仍然显示标准控件。

具有标准传输控件的 MediaElement:

<MediaElement AreTransportControlsEnabled="True">

</MediaElement>

打开 Blend 或在 VS2015 上单击“查看”->“其他”Windows->“文档大纲”(ctrl+alt+T)

在 xaml

中添加 MediaTransportControls
 <MediaTransportControls />

不要转到文档大纲并右键单击 MediaTransportControls -> 编辑模板 -> 编辑副本(我有一个 styles.xaml 我选择将它放在那里,你可以单击确定)

现在,文档大纲将视图更改为 MediaTransportControls 模板,您可以根据自己的喜好进行更改。前任。我在中间加了个play/pause

在 Blend 中执行此操作可让您更好地访问,例如编辑状态。

完成自定义后,您可以像这样将其添加到您的 MediaElement 中

 <MediaElement x:Name="mediaElement" AreTransportControlsEnabled="True" >
      <MediaElement.TransportControls>
             <MediaTransportControls Style="{StaticResource MediaTransportControlsStyle1}"/>
      </MediaElement.TransportControls>
</MediaElement>

既然要添加 selector 标准传输控制和 select 视频质量,我认为仅编辑模板是不够的。

To add to or modify the functionality of the transport controls, you must create a new class that's derived from MediaTransportControls.

要创建从 MediaTransportControls 派生的新 class:

  1. Add a new class file to your project.
  2. Modify the class code to derive from the MediaTransportControls class.
  3. Copy the default style from MediaTransportControls styles and templates into a ResourceDictionary in your project. This is the style and template you modify.
  4. Change the TargetType of the style to the new custom control type.
  5. Set the DefaultStyleKey of your custom class.
  6. Add a MediaElement to your XAML markup and add the custom transport controls to it.

有关详细信息,请参阅 GitHub 中的 Create custom transport controls and also the official Media transport controls sample