Caliburn Micro: Disable button when form validation fails

I have a form with a text field attached to an integer and a button. Now that the value of the text field is invalid, I want to immediately disable the button.

Typically, you can put the Can () method in a virtual machine and run the NotifyOfPropertyChange mechanism in setting properties. However, if the user enters a non-numeric value, for example, the text field is invalid, but the property setting tool is never called, so I can notify / disable the button.

So, how to disable the button when the user enters an invalid value that does not lead to a call to the property setting tool? My knowledge of CM is limited since I just started.

+3
source share
2 answers

I found that the best approach to this problem is to make the property a string instead, and make the desired string for integer conversion to its set of properties. If the conversion is not valid, you can reset the TextBox to the default value. Thus, your interlocutor will always be fired.

If your model has an integer property, then it makes sense to place the version of the string in the view model, since this is really only related to the user interface, and not to the business logic.

If you do not want the user to enter non-character characters, you can use a hidden text field, for example, in the Extended WPF Toolkit or in a package of third-party controls, for example, Telerik or Infragistics.

+4

MaskedTextBox .

0

All Articles