我放弃了,我怎么投这个?
class AmountIsTooHighConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//int amount = (int)value;
//int amount = (int)(string)value;
//int amount = (int)(value.ToString);
//int amount = Int32.Parse(value);
//int amount = (int)Convert.ChangeType(value, typeof(int));
//int amount = Convert.ToInt32(value);
if (amount >= 35)
{
return true;
}
else
{
return false;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
最佳答案
Convert.ToInt32
或 Int32.Parse
都应该工作...如果他们不工作,那么该值肯定不是 int ;)
尝试在你的转换器中放置一个断点来观察值,它可能会告诉你为什么它不起作用
关于c# - 如何在转换器中将对象转换为 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/915457/