应用一
Converter
比如下面的绑定就应该做到这一点:
public class TextConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
int actual = (int)value;
return actual.ToString();
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
string actual = (string)value;
int theValue = 0;
int.TryParse(actual, out theValue);
return theValue;
}
}
你的
TextBox
绑定如下所示:
<TextBox Text="{Binding ... Converter={StaticResource convert}}"></TextBox>
将转换器定义为窗口/控件的资源。