簡體   English   中英

使用轉換器XAML的'System.Exception'類型的異常

[英]An exception of type 'System.Exception' using a converter XAML

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

我想念什么?

我想通了..我必須在Application.Resources部分中包含SecondsToMinutesHour轉換器的引用

....  
<Application.Resources>
    <settings:AppSettings x:Key="AppSettings" />
    <app:SecondsToMinutesHour x:Key="SecondsToMinutesHour" />
....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM