我正在通过隐藏代码调用 IValueConverter 类,但我不确定要在 Type targetType
参数中放入什么。对象是 string
但使用它会给我“无效的表达式术语‘string’”
我调用转换器的代码
secondConverter.Convert(score, string, null, CultureInfo.CurrentCulture);
转换器类
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);
}
最佳答案
您可以放置 typeof(string)
而不是字符串,但您的转换器似乎不使用或验证目标类型,因此您可以放置任何内容,包括 null。
通常,您的转换器至少应验证目标类型是否为字符串,如果不是则抛出异常。
关于c# - 在 IValueConverter 的 Type targetType 参数中输入什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16061489/