私はあきらめて、これをどのようにキャストしますか?Converterでオブジェクトをintにキャストするにはどうすればよいですか?
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;
}
}
に解析する前に文字列に変換することをお勧めします。オブジェクトがIConvertibleを実装している場合、Convertは機能します。 –
あなたはそうです。Parseはオブジェクトではなく文字列を取ります。 –
Convert.ToInt32()とInt32.Parseは、すべての値をコンマで "2,000"のように解析しません。私はFormatExceptionの試しとキャッチをお勧めします – abhilash