【发布时间】: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