我在我的 Windows Phone 应用程序中使用 XAML 中的 IValueConverter。我的代码
<TextBlock Margin="0,0,10,0"
Text="{Binding Score, Converter={StaticResource SecondsToMinutesHour}}"
Foreground="{Binding DeviceID, Converter={StaticResource FontForegroundConverter}}"
FontWeight="{Binding DeviceID, Converter={StaticResource FontWeightConverter}}"
Grid.Column="3" />
但是转换器引发了这个错误
An exception of type 'System.Exception' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
分数是一个类型字符串,我的转换器类如下
public class SecondsToMinutesHour : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int secs = int.Parse(value.ToString());
TimeSpan ts = TimeSpan.FromSeconds(secs);
return String.Format("{0:D2}:{1:D2}:{2:D2}",
ts.Hours,
ts.Minutes,
ts.Seconds);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
我错过了什么?