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

Score は文字列型で、私のコンバーター クラスは次のとおりです。

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