【问题标题】:Text not update onTransportControl from MediaPlayerElement (UWP)文本未从 MediaPlayerElement (UWP) 更新 onTransportControl
【发布时间】:2019-12-20 06:47:54
【问题描述】:

我尝试像这些代码一样将视频标题放在 MediaPlayerElement 的 TransportControl 上

MediaTransportControlsStyle.xaml

...
 <TextBlock
    Name="tblTitle"
    Grid.Column="1"
    Margin="5"
    FontFamily="Arial"
    FontSize="22"
    FontWeight="SemiBold"
    TextAlignment="Center" />
...

PlayerPage.xaml.cs

private async void MediaPlayer_MediaOpened(MediaPlayer sender, object args)
{
    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    {
        FrameworkElement transportControlsTemplateRoot = (FrameworkElement)VisualTreeHelper.GetChild(player.TransportControls, 0);
        TextBlock tblTitle = (TextBlock)transportControlsTemplateRoot.FindName("tblTitle");
        if (tblTitle != null)
            tblTitle.Text = MediaTitle; // Debug can run to this line
    });
}

问题是 tblTitle 只是更新第一次应用导航到 PlayerPage.xaml 页面。从第二次开始 tblTitle 即使调试运行到该行也保持空白

tblTitle.Text = MediaTitle; // Debug can run to this line

我想我与 Dispatcher.RunAsync 方法有关以更新 UI 线程。我尝试了几种方法,但没有运气。我该如何解决这个问题?

【问题讨论】:

    标签: c# xaml uwp win-universal-app windows-10-universal


    【解决方案1】:

    我发现我在进入 PlayerPage 时没有重新初始化 MediaPlayer。每次都初始化就完成了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多