I want the user to be able to enter e.g. 310312 and have the text property of a datepicker updated to 31/03/12 automatically; I've bound the datepicker to a view model 'Date' property as below.
With WPF4.0, binding now automatically performs a get after a set (no need for INotifyPropertyChanged); this is happening in the code below but although the 'get' date field value is the correct '31/03/12', the datepicker text property is not updating, and remains at 310312 (NB UpdateSourceTrigger=PropertyChanged).
The textbox property does change (e.g. where the set code, not shown, converts to Uppercase)
I would really appreciate some pointers as to why this is.
<Grid>
<DatePicker Text="{Binding Path=Date,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Height="25" HorizontalAlignment="Left" Name="datePicker1"/>
<TextBox Text="{Binding Path=State,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="23" HorizontalAlignment="Left" Name="textBox1" />
</Grid>
private string date;
public string Date
{
get
{
return date;
}
set
{
if (value != null)
{
Regex abbreviatedDateFormat = new Regex(@"\A\d{6}\Z");
if (abbreviatedDateFormat.IsMatch(value))
{
value = value.Insert(2, "/");
value = value.Insert(5, "/");
}
}
date = value;
}
}