0

我在我的 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();
    }
}

我错过了什么?

4

1 回答 1

0

我想通了..我必须在该部分中包含SecondsToMinutesHour转换器的参考Application.Resources

....  
<Application.Resources>
    <settings:AppSettings x:Key="AppSettings" />
    <app:SecondsToMinutesHour x:Key="SecondsToMinutesHour" />
....
于 2013-04-18T04:59:18.143 回答