This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I created DataTemplate for my Type <DataTemplate x:Key='ConstrainEditor'> added it to PropertyGrid editors <ms:PropertyGrid.Editors> </ms:PropertyGrid.Editors> if FormatException thrown in my convertor ConvertBack, PropertyGrid doesn catch it and program terminates public object ConvertBack(object value, Type type, object par, CultureInfo culture) ... ... |
|
|
Unfortunately, WPF controls, including the property grid, can't catch exceptions in value converters because they aren't on the stack at this point: the value converter is being called by the WPF data binding infrastructure itself. Rather frustratingly, you can't even catch them with the Binding.ValidatesOnExceptions property -- this only works for exceptions raised by the data source. From MSDN (emphasis added):
So you have to write value converters very defensively. What I often do is, if I can't do the conversion, I have the value converter return the original value, which WPF then fails to convert to the binding source type, resulting in an exception at the source, which I can then pick up using ValidatesOnExceptions and provide appropriate UI for. |
|
|
Correct that solves the problem <DataTemplate x:Key='xxxEditor'> Converter derives from ValidationRule public class MyConverter: ValidationRule, IValueConverter public object ConvertBack(object value, Type type, object par, CultureInfo culture) ..... |
|