I have a class, called DateField
, that has a string Value
property. If you set this property to a string that can be parsed into a valid date, the property setter sets Value
to the properly formatted date, e.g.:
private string _Value;
public string Value
{
get
{
return _Value;
}
set
{
if (value == _Value)
{
return;
}
object result;
if (TryParse(value, out result))
{
_Value = Format(result);
}
else
{
_Value = value;
}
OnPropertyChanged("Value");
}
}
I create a TextBox that's bound to this field:
<DataTemplate DataType="{x:Type m:DateField}">
<TextBox
IsTabStop="True"
Text="{Binding Value, Mode=TwoWay, ValidatesOnDataErrors=True}">
</TextBox>
</DataTemplate>
When I enter, say, "010109"
into this field and tab out of it, the Binding
appropriately sets the Value
property to this string. The property setter runs, _Value
gets correctly set to "01/01/2009"
(the TryParse
implementation in this class is a little more catholic in what it accepts than DateTime.TryParse
is), and the PropertyChanged
event gets raised. I know this last bit is happening because another object that's subscribed to the list gets updated.
But the TextBox
doesn't. Why not? I've set Value
, I've raised PropertyChanged
; what more do I need to be doing?