vijay.k
vijay.k

Reputation: 179

Binding double to Textbox with validation in windows store apps

I am using prism for windows 8 the BindableBase class to validate the properties, till now I can bind the string properties and validate them with custom validator.

Now I want to bind the double value directly to the view with two way binding.the problem is when user enters any alphabetical character then the setter of that double property doesn't gets fire cause its not a double value and might fires a conversion exception but because of that I cant validate my property.

may I go for the converter ?, but how can I raise validation exception and make the property invalid in converter

Does anyone know how to do this?

Upvotes: 0

Views: 263

Answers (1)

Bart
Bart

Reputation: 10015

Two way binding a double does indeed give some issues in Windows Store apps (input validation, localization, ...). What I usually do is have another property that represents this double as a string and bind the string value. You can also add validation on this string property and check if it does parse to a double with double.TryParse().

Hopefully a better solution for Windoew 10 UWP will be announced in the near future to prevent the need for this hack.

Upvotes: 1

Related Questions