自定义 MediaTrasportControls 不可见

图明

我需要在 MediaPlayerElement 中实现自定义控件。我遵循了“创建自定义传输控件”Microsoft 指南,并尝试自己一步一步地制作所有内容,甚至公然从示例应用程序中复制代码。但这些都没有奏效。

我只看到没有任何控件的 MediaPlayerElement。然后我试着少走。我创建了一个新项目并尝试自己复制示例应用程序。嗯,它也失败了。我记得我在某处有错误,但我看不到那里。三重检查所有内容,甚至将默认样式复制到我的“自定义”样式中。但是,仍然没有面板。

控制类:

namespace Kinopub.UI.Utilities
{
    public sealed class CustomMediaTransportControls : MediaTransportControls
    {
        public event EventHandler<EventArgs> Liked;

        public CustomMediaTransportControls()
        {
            this.DefaultStyleKey = typeof(CustomMediaTransportControls);
        }

        protected override void OnApplyTemplate()
        {
            // This is where you would get your custom button and create an event handler for its click method.
            Button likeButton = GetTemplateChild("LikeButton") as Button;
            likeButton.Click += LikeButton_Click;

            base.OnApplyTemplate();
        }

        private void LikeButton_Click(object sender, RoutedEventArgs e)
        {
            // Raise an event on the custom control when 'like' is clicked
            Liked?.Invoke(this, EventArgs.Empty);
        }
    }
}

控制资源字典:(完整代码)

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Kinopub.UI.Utilities">

    <!-- Default style for MediaTransportControls -->
    <Style TargetType="local:CustomMediaTransportControls">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="FlowDirection" Value="LeftToRight" />
        <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
        <Setter Property="IsTextScaleFactorEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:CustomMediaTransportControls">
                    <Grid x:Name="RootGrid" Background="Transparent">

                        ...
                            A whole lot of code, copied from generic.xml
                        ...

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

媒体播放器页面:

<Page
    x:Class="Kinopub.UI.Views.MediaPlayerPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Kinopub.UI.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vms="using:Kinopub.UI.ViewModels"
    xmlns:utils="using:Kinopub.UI.Utilities"
    mc:Ignorable="d"

    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.DataContext>
        <vms:MediaPlayerVM/>
    </Page.DataContext>
    <Grid>
        <MediaPlayerElement
            x:Name="PlayerElement"
            Source="{Binding VideoMediaSource}"
        HorizontalAlignment="Stretch"
        VerticalAlignment="Bottom"
        AreTransportControlsEnabled="True"
        >
            <MediaPlayerElement.TransportControls>
                <utils:CustomMediaTransportControls>
                </utils:CustomMediaTransportControls>
            </MediaPlayerElement.TransportControls>
        </MediaPlayerElement>
    </Grid>
</Page>
Richard Zhang - MSFT

通过检查您的代码,您需要注意两件事。

  1. 将在 下创建的资源字典添加Kinopub.UI.UtilitiesApp.xaml,例如:
<Application ...>
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ms-appx:///Kinopub/UI/Utilities/resource_file_name.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
  1. 像这样添加一个AppBarButton名为LikeButton 的按钮ControlTemplate
<CommandBar x:Name="MediaControlsCommandBar" ...>
    ...
    <AppBarButton x:Name="LikeButton"
                  Icon="Like"
                  Style="{StaticResource AppBarButtonStyle}"
                  MediaTransportControlsHelper.DropoutOrder="3"
                  VerticalAlignment="Center"
                  />
    ...
</CommandBar>

最好的祝福。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

自定义视图不可见

来自分类Dev

AWS CloudWatch自定义指标数据不可见

来自分类Dev

自定义UIView在addSubview上不可见

来自分类Dev

SharePoint 2013自定义Web部件不可见

来自分类Dev

自定义ListView项几乎不可见

来自分类Dev

使自定义视频控件不可见

来自分类Dev

Expandablelistview自定义指标不可见

来自分类Dev

自定义控件在Winform上不可见

来自分类Dev

clang:AST中不可见的自定义属性

来自分类Dev

Swift 结构在自定义框架中不可见

来自分类Dev

为什么我的自定义视图不可见?

来自分类Dev

android自定义拖动阴影不可见

来自分类Dev

React Native Navigator:自定义组件不可见

来自分类Dev

自定义 UITableViewCell 中的 UIView 不可见

来自分类Dev

自定义视图(xib)在情节提要板上不可见

来自分类Dev

在设计器模式下,来自Nuget的不可见Windows 8.1自定义控件

来自分类Dev

自定义列表视图中的2个按钮应该不可见

来自分类Dev

在PublisherAdView中使用自定义广告尺寸时,Google广告不可见

来自分类Dev

自定义TableViewCell内容在iOS9 Xcode7上不可见

来自分类Dev

光标在KitKat上的空自定义EditText中不可见

来自分类Dev

叮当声:AST中不可见的自定义属性

来自分类Dev

自定义子组件已添加但不可见

来自分类Dev

自定义模板在shopify的模板后缀部分中不可见

来自分类Dev

在设计器模式下,来自Nuget的不可见Windows 8.1自定义控件

来自分类Dev

自定义列表视图中的2个按钮应该不可见

来自分类Dev

导航抽屉图标在自定义操作栏上不可见?

来自分类Dev

自定义SimpleCursorAdapter和BindView(按钮随机不可见)

来自分类Dev

应用基本自定义样式后按钮不可见-WPF

来自分类Dev

PySide 中 QListView 的自定义 ItemDelegate:项目不可见

Related 相关文章

  1. 1

    自定义视图不可见

  2. 2

    AWS CloudWatch自定义指标数据不可见

  3. 3

    自定义UIView在addSubview上不可见

  4. 4

    SharePoint 2013自定义Web部件不可见

  5. 5

    自定义ListView项几乎不可见

  6. 6

    使自定义视频控件不可见

  7. 7

    Expandablelistview自定义指标不可见

  8. 8

    自定义控件在Winform上不可见

  9. 9

    clang:AST中不可见的自定义属性

  10. 10

    Swift 结构在自定义框架中不可见

  11. 11

    为什么我的自定义视图不可见?

  12. 12

    android自定义拖动阴影不可见

  13. 13

    React Native Navigator:自定义组件不可见

  14. 14

    自定义 UITableViewCell 中的 UIView 不可见

  15. 15

    自定义视图(xib)在情节提要板上不可见

  16. 16

    在设计器模式下,来自Nuget的不可见Windows 8.1自定义控件

  17. 17

    自定义列表视图中的2个按钮应该不可见

  18. 18

    在PublisherAdView中使用自定义广告尺寸时,Google广告不可见

  19. 19

    自定义TableViewCell内容在iOS9 Xcode7上不可见

  20. 20

    光标在KitKat上的空自定义EditText中不可见

  21. 21

    叮当声:AST中不可见的自定义属性

  22. 22

    自定义子组件已添加但不可见

  23. 23

    自定义模板在shopify的模板后缀部分中不可见

  24. 24

    在设计器模式下,来自Nuget的不可见Windows 8.1自定义控件

  25. 25

    自定义列表视图中的2个按钮应该不可见

  26. 26

    导航抽屉图标在自定义操作栏上不可见?

  27. 27

    自定义SimpleCursorAdapter和BindView(按钮随机不可见)

  28. 28

    应用基本自定义样式后按钮不可见-WPF

  29. 29

    PySide 中 QListView 的自定义 ItemDelegate:项目不可见

热门标签

归档