I have a Telerik RadDataForm, with a couple of DataFormDataField's that are bound to nullable properties:
<telerik:DataFormDataField Label="My Property">
<telerik:RadNumericUpDown Value="{Binding Path=MyProperty}" />
</telerik:DataFormDataField>
And:
private double? myProperty;
public double? MyProperty
{
get { return this.myProperty; }
set
{
this.myProperty = value;
this.onPropertyChanged(nameof(this.MyProperty));
}
}
And:
public event PropertyChangedEventHandler PropertyChanged;
private void onPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
When the form loads, the property is null, so the control is empty. If the user types or uses the control to put a number into the property, the control displays the value and the property is set to the correct value.
I need to be able to reset the property to null in code and have the control cleared again. Unfortunately, when I set the property to null, the control does not change and continues to contain the prior value.
Any ideas as how to make this happen?
=== ADDENDUM ===
To clarify whether this was a problem in Telerik's RadNumericUpDown control, or in basic WPF binding, I replaced it with IntegerUpDown from Alex Titarenko's WPFControls:
<telerik:DataFormDataField>
<xctk:IntegerUpDown Value="{KtWpf:IntegerBinding Path=mileageend}" />
</telerik:DataFormDataField>
I'm seeing exactly the same behavior.
=== OOPS ===
OK, the problem had nothing to do with the binding. Buried in the code for the view model that backed the control that contained this data form, we'd new up the object that the data form was bound to.
What was happening was that before we got to the code that set these fields to new, we'd new up a new object and point the view model's reference to it. So when I walked through in the debugger, I was looking at one object, and was setting its fields to null, but the data form was still bound to the original, which wasn't being changed.
When I null the fields of the object that the data form is actually bound to, everything works fine.
Sorry, everyone, for the distraction, and thanks for the help.
One bit of advice - when what is happening seems to make no sense, it may be that what is happening isn't what you think is happening.