0

I am using a IValueConverter in XAML in my Windows Phone app. My code

<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" />

However the Converter raised this error

An exception of type 'System.Exception' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary

Score is a type string and my converter class is as follow

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

What am I missing?

Daniel
  • 10,864
  • 22
  • 84
  • 115
PutraKg
  • 2,226
  • 3
  • 31
  • 60

1 Answers1

0

I figured it out.. I have to include a reference of the SecondsToMinutesHour converter in the Application.Resources section

....  
<Application.Resources>
    <settings:AppSettings x:Key="AppSettings" />
    <app:SecondsToMinutesHour x:Key="SecondsToMinutesHour" />
....
PutraKg
  • 2,226
  • 3
  • 31
  • 60