【发布时间】:2018-07-07 12:53:43
【问题描述】:
我有一个媒体播放器元素,它使用 PosterSource(如 ImageSource)作为我正在开发的 UWP 应用程序。代码如下所示:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<MediaPlayerElement x:Name="MainMPE" AreTransportControlsEnabled="True" AutoPlay="True" PosterSource="{Binding PosterSource}">
</MediaPlayerElement>
</Grid>
在我的代码中,我对PosterSource 进行了以下设置
public sealed partial class PlayerView : Page, INotifyPropertyChanged
{
private ImageSource _PosterSource;
public event PropertyChangedEventHandler PropertyChanged;
public ImageSource PosterSource
{
get => _PosterSource;
set
{
if (_PosterSource != value)
{
_PosterSource = value;
RaisePropertyChanged(nameof(PosterSource));
}
}
}
private async void PlayerView_Loaded(object sender, RoutedEventArgs e)
{
await SetPoster();
// other code to load PlayerView
}
private async Task SetPoster()
{
var tempBitamp = new BitmapImage();
await tempBitamp.SetSourceAsync(/* Stream comes from anotehr object */);
PosterSource = tempBitamp;
}
private void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
我的问题是它没有更新。图像永远不会加载。如果我直接从代码中调用 MainMPE.PosterSource 对象并将其设置为我的 BitmapImage,它可以工作,但我试图让它与 Bindings 一起正常运行。我在这里做错了什么?
【问题讨论】: