I follow this example from MSDN
Handle errors and exceptions that occur when binding data ( the same example is also here )
The idea behind this example is:
- TextBox controls are bound to the properties of the business object using
BindingSourceand Binding. A business object is a Model. - The property devices in the business object validate the input and throw exceptions when the inputs are invalid.
- Binding objects are configured to catch such exceptions.
- Binding triggers an event
BindingComplete. If an exception occurs, it has been detected and the exception message is available through BindingCompleteEventArgs. Validation error messages may return to the presentation level this way.
So far - so good.
Here's the odd part. The exception trap created by the business object varies for different versions of .NET.
- This works with .NET version 3.5. An exception is binding. The event is
BindingCompletefired. Arguments of the event indicate that the binding was not successful. As expected. - .NET versions 4.0, 4.5, 4.5.2 do not catch an exception in the set of model properties. Execution aborts on this exception.
The same source code is copied from a Microsoft example. I only change the version of .NET in the project properties.
A:
: (2009)
A MSDN (2010), Binding.Parse.
[, , e.Cancel true Control.Validating. ?]
B:
.
. , . , .
, . ?
- WinForms. WPF?
WinForms - .