0
我有這樣的轉換器下面應該根據內部的字符數返回TextBox
的寬度:變換器,發送一個字符串並返回一個INT
[ValueConversion(typeof(String), typeof(int))]
public class TextToWidth:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
String g = (String)value;
return g.Length*10;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
在網格的ColumnDefinition,我試圖使用此轉換器,但收到錯誤 TypeConverter爲IValueConverter
不支持從字符串轉換。我知道Controls:TextboxHelper.Label
是一個字符串:
<ColumnDefinition Width="{TemplateBinding Controls:TextboxHelper.Label, Converter=ToWidth}"/>
爲什麼會出現這種情況,是有什麼解決辦法?
是確切的錯誤您收到?如果不是,請複製並粘貼錯誤。 TextboxHelper.Label是一個字符串還是控件? – TyCobb 2014-10-08 18:47:02