0

I have a textbox with a validator that permits only integer values. How do I check if text in my textbox represents a correct integer value without checking the text itself?

I am using Prism MVVM so I would like to hear some solution like "bind a validator property to your viewmodel/model code", but a generic WPF solution is also fine.

The problem is that I can't get the incorrect value in my model / viewmodel. If the value is incorrect, then the underlying binded property doesn't get set.

1 Answer 1

1

You could use IDataErrorInfo, or Data Annotations. The Data Annotations Extensions project contains an Integer attribute.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 for IDataErrorInfo. Even if you use DataAnnotations, you should still use IDataErrorInfo as well since WPF is built to work with it.
I don't see how I can use IDataErrorInfo. I can't get the incorrect value in my model or viewmodel, I can see only the correct value. If current value is incorrect, then it won't get passed to the viewmodel/model.
See stackoverflow.com/questions/9157894/…. You could use an IValueConverter to always return a valid integer so that your view model is updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.