I give up how to do this?
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; } }
Both Convert.ToInt32, or Int32.Parsehave to work ... If they do not, then it's definitely not int;)Try to set a breakpoint in the converter to see the value, it can show you why it's not working.
Convert.ToInt32
Int32.Parse
If the value is actually a string object (with content representing an integer value), this gives the least overhead:
int amount = Int32.Parse((string)value);
Convert.ToInt32 , int, , , , int.
int
Place the breakpoint in the opening bracket of your Convert method. Run the application in debug mode. When a breakpoint hits, analyze the actual type of value. Take a throw. If the value is a string, then pass it to the string and then parse the result to get an integer. Run the program again. It should work this time.
If the value is an object, ToString()it is best to convert to a string before parsing toInt int amount = Int32.Parse(value.ToString());
ToString()
Int int amount = Int32.Parse(value.ToString());
Source: https://habr.com/ru/post/1709186/More articles:Registration for expired timer events - c #Flex / Flash: how to embed the same font in multiple SWC - flexLoading a 32-bit process in a 64-bit environment - javascriptHow to create a delete command for a Windows-based application in the application folder - vb.netHow to connect from Ruby to MS Sql Server - ruby | fooobar.comHow to pass variables from form to form? - vb.netWhy doesn't this ActiveRecord link work? - ruby-on-railsHow to get groups included in an ActiveDirectory group using C #? - c #CAML cannot reference custom properties in custom fields - sharepointCan I create read-only items in SOAP web services? - c #All Articles