我需要根据内容获得宽度的确切值,基本上我就是这样:
<Setter Property="Width" Value="{Binding Match1, Converter={StaticResource NameToWidthConverter}}" />
我创建了一个这样的转换器:
public class NameToWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var input = value as string;
switch (input)
{
case "V":
return 20;
case "N":
return 20;
case "P":
return 20;
default: //Larghezza per risultati
return "Auto";
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
这样做有效,但在编译器中返回Auto
时出现此错误:
ystem.Windows.Data错误:6:&#39; DynamicValueConverter&#39;转换器未能转换值&#39; Auto&#39; (键入&#39; String&#39;);
然而,正确应用了Auto值,那有什么不对?
答案 0 :(得分:0)
您无法返回&#34;自动&#34;,您只需返回Double.NAN。