Search code examples
bindingsilverlight-5.0ivalueconverter

Convert Text value to Integer using IValue converter


In my application i am binding a integer to a gridview column.

Scenario : In the cell edit mode of gridview, if the user types some string values like A+,A. i want text to convert it automatically to integer value.

I am having a collection where each string value will be having a integer assigned.

In the converter i want to check for that and show its corresponding integer value.

Can it be done using IValueConverter


Solution

  • Yes, it makes sense to do this in a value converter.

    Out-of-the-box, .NET does not provide any classes or methods for parsing the expression into its numerical equivalent, but you should be able to use numerical parsing libraries like for example NCalc or Simple Math Parser to "do the job" for you.

    I honestly don't know if these libraries are immediately available for Silverlight, but if not it is probably worth the effort to port them to SL yourself, rather than writing your own math parser.