我在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();
}
}
我错过了什么?
答案 0 :(得分:0)
我弄清楚了..我必须在SecondsToMinutesHour
部分中添加Application.Resources
转换器的引用
....
<Application.Resources>
<settings:AppSettings x:Key="AppSettings" />
<app:SecondsToMinutesHour x:Key="SecondsToMinutesHour" />
....