3

So I'm messing around a bit with Caliburn.Micro, and suddenly I notice something interesting.

I have a ViewModel property called Maximum of type int, auto bound with CM via the naming convention, to a TextBox.

When I enter something that is not and integer, i.e. a character, the textbox' border turns red, and the setter of the property is not called.

Is this an auto-feature of CM?

kasperhj
  • 10,052
  • 21
  • 63
  • 106
  • 1
    Not as far as I know... there's no validation mechanism built in to CM. This is probably just a feature of the textbox/binding mechanism - have you tried it without CM? – Charleh May 21 '13 at 13:21

1 Answers1

3

No, this is the behaviour of WPF. One option is to bind to a string property on your view model, and then perform the validation within the view model (i.e. parse to an int, and provide a default value if the parse fails).

devdigital
  • 34,151
  • 9
  • 98
  • 120
  • Thanks for answering. Is there a way to disable this behavior? – kasperhj May 21 '13 at 20:34
  • 1
    Another option is to use a nullable int and set the TargetNullValue to an empty string on the TextBox, see http://stackoverflow.com/a/1895482/83111 – devdigital May 21 '13 at 21:04