I am binding a datagrid to a BindingList of TransectPoint objects (it doesn't matter what a TransectPoint is for this question).
One of the properties of a TransectPoint is AverageSenescentCrownRadiusProperty (code is below). Note in particular that the value of the property must be > 0 (or null) - as enforced by DoubleIsPositive.
When editing data in the grid, it will work (almost) perfectly - if I enter a negative value (eg -5) in the column related to this property then the background of the cell will go red. If I hover over the cell it shows this tooltip:
'-5' is not a valid value for property 'AverageSenescentCrownRadiusProperty'.
Is there a way to customise the message that is displayed (since I would rather the user not see 'AverageSenescentCrownRadiusProperty')?
CODE IS BELOW
public static readonly DependencyProperty AverageSenescentCrownRadiusProperty = DependencyProperty.Register("AverageSenescentCrownRadius", typeof(double?), typeof(TransectPoint), new PropertyMetadata(new double?(0f)), new ValidateValueCallback(DoubleIsPositive));
[XmlElement("AverageSenescentCrownRadius")]
public double? AverageSenescentCrownRadius
{
get { return (double?)GetValue(AverageSenescentCrownRadiusProperty); }
set { SetValue(AverageSenescentCrownRadiusProperty, value); }
}
private static bool DoubleIsPositive(object value)
{
double? tempDouble = (double?) value;
if (tempDouble.HasValue)
return tempDouble >= 0;
else
return true;
}