【发布时间】:2014-07-04 06:36:01
【问题描述】:
我正在开发一个使用后台任务播放音频的 Windows Phone 8.1 项目,我想将 UI 元素绑定到 BackgroundMediaPlayer.Current(即 MediaPlayer 类)的属性。
在我的 Xaml 代码中,我有这个 TextBlock 元素
<TextBlock x:Name="CurrentTime" FontSize="12" HorizontalAlignment="left"
Text="{Binding Position, Converter={StaticResource TimeSpanConverter}}"
Style="{StaticResource ListViewItemSubheaderTextBlockStyle}"/>
这是转换器类:
class TimeSpanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (!(value is TimeSpan))
{
return String.Empty;
}
return ((TimeSpan)value).ToString("mm':'ss");
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
在我后面的代码中,我这样设置 TextBlock 的数据上下文:
MediaPlayer _mediaPlayer = BackgroundMediaPlayer.Current;
CurrentTime.DataContext = _mediaPlayer;
问题是,我在用户界面中的控件没有更新为 MediaPlayer.Position 的值,我的代码有什么问题?感谢您的帮助。
【问题讨论】:
标签: c# xaml windows-phone-8 data-binding binding