IDataErrorInfo Validation overridden by PropertyGrid

Grids for WPF Forum

Posted 8 years ago by Pat Maneely - Software Engineering Manager, Cobham Aerospace
Avatar
The Object that is being displayed by the PropertyGrid has its own IDataErrorInfo validation logic.

This object contains UInt16 types, which I want to validate. I looks like however that when this UInt16 value is out of range (-1 is typed into the text box), that the IDataErrorInfo Validation gets to it first and throw an exception.

When my validation processes it it see a valid value. This results in the internal exception message being displayed in the tooltip as opposed to my error message.

Is there a way to prevent this?


Here's the output from the debugger Output Window

The thread 0xe70 has exited with code 0 (0x0).
The thread 0x103c has exited with code 0 (0x0).
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=Value; DataItem='PropertyGridDataAccessorItem' (Name=''); target element is 'TextBox' (Name='textBox'); target property is 'Text' (type 'String') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: 900000 is not a valid value for UInt16. ---> System.OverflowException: Value was either too large or too small for a UInt16.
at System.UInt16.Parse(String s, NumberStyles style, NumberFormatInfo info)
at System.ComponentModel.UInt16Converter.FromString(String value, NumberFormatInfo formatInfo)
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
--- End of inner exception stack trace ---
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyDescriptorDataAccessor.set_ValueInternal(Object value)
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.CachedPropertyDataAccessorBase.set_Value(Object value)
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyGridDataAccessorItem.set_Value(Object value)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
at MS.Internal.Data.ClrBindingWorker.UpdateValue(Object value)
at System.Windows.Data.BindingExpression.UpdateSource(Object value)'

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Pat,

Unfortunately, no. The IDataErrorInfo is only useful in ensuring that the values are correct. It can't be used to detect if you try to assign -1 to a UInt16, which is effectively what is happening.

You would either have to use a type such as Int32, and validate that it fits into a UInt16. Or use a custom property editor that adds a custom ValidationRule to the binding between the TextBox and the IPropertyDataAcessor.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.