2013-04-18 72 views
0

我在Windows Phone應用程序的XAML中使用了IValueConverter。我的代碼使用轉換器的'System.Exception'類型的異常XAML

<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

我計算出來..我必須包括在Application.Resources部所涉及的轉換器SecondsToMinutesHour的參考

.... 
<Application.Resources> 
    <settings:AppSettings x:Key="AppSettings" /> 
    <app:SecondsToMinutesHour x:Key="SecondsToMinutesHour" /> 
.... 
相關問題