Put*_*aKg 2 c# types ivalueconverter windows-phone-8
我通过代码后面调用一个IValueConverter类,但我不知道该在Type targetType参数中添加什么.该对象string只是使用它给我'无效的表达术语'字符串'
我调用转换器的代码
secondConverter.Convert(score, string, null, CultureInfo.CurrentCulture);
Run Code Online (Sandbox Code Playgroud)
转换器类
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
TimeSpan ts = new TimeSpan(0, 0, (int)value);
return String.Format("{0:D2}:{1:D2}:{2:D2}",
ts.Hours,
ts.Minutes,
ts.Seconds);
}
Run Code Online (Sandbox Code Playgroud)
您可以放置typeof(string)而不是字符串,但您的转换器似乎没有使用或验证目标类型,因此您可以放置任何内容,包括null.
通常,您的转换器至少应验证目标类型是否为字符串,如果不是则抛出异常.
| 归档时间: |
|
| 查看次数: |
2522 次 |
| 最近记录: |