I have a form with some textboxes in them that are bound to their properties in the VM through caliburn’s automatic bindings. However if you type something on the textbox that does not make sense for the binding Caliburn simply does nothing with it ( or so I see it as ).
What I want to know if there is a way for Caliburn to constrain input to its binding in someway. For example:
I have a TextBox that is bound to a TimeSpan in the VM.
Writing 00:00:10 works fine and sets the TimeSpan to 10 seconds.
If I would write 00:00:-10 nothing happens and the binding remains at the previous value that did properly bind.
Your issue is not related to Caliburn.Micro that simply helps you connect your view to your view-model using data binding. What you need to use is validation of the data binding. You can read more about data binding in Silverlight in particular the Data Validation section is what you should study.
Caliburn.Micro automatically creates bindings using conventions. However, you may have to customize these bindings in XAML to get the desired validation behavior.
In the case where you write
00:00:-10your validation fails because an exception is thrown from the binding engine’s type converter. If the binding expression for theTextBoxhas a ValidatesOnExceptions property value set to true you will get visual feedback that the value is invalid. And because the entered value couldn’t be converted to aTimeSpanno change is made to the view-model.