Hello,
i've made a binding from a TextBox to a Property. If the user write a date-value into the TextBox, it should be automatically corrected. f.e.: 20.01.10 -> 20.01.2010
The correction is done in the propertys set-block:
public String DateOfBirth
{
get
{
if (patient.DateOfBirth != DateTime.MinValue)
return patient.DateOfBirth.ToString("dd.MM.yyyy");
else
return patient.BirthdayString;
}
set
{
string dateParsed = ValidateDatePart(value, false, true);
DateTime date = new DateTime();
DateTime.TryParse(dateParsed, out date);
patient.DateOfBirth = date;
patient.BirthdayString = dateParsed;
base.OnPropertyChanged("DateOfBirth");
}
}
patient.DateOfBirth
and patient.BirthdayString
are values in the datamodel of my application. The return of birthday as string is needed, because the user should be able to input parts of a birthday, f.e. if the birthday is not fully known like '12.1967'.
My Problem is that, if the user input a date like '20.01.10', this date is corrected in the property, but the corrected date ('20.01.2010') is not set to the TextBox. The TextBox contains still '20.01.'
Does anybody have an idea, how the TextBox can be updated? The binding mode should be TwoWay by default.
Here's the XAML for the TextBox:
<TextBox Validation.ErrorTemplate="{StaticResource errorTemplate}" Style="{StaticResource NotEmptyTextBox}">
<Binding Path="OrderVM.Patient.DateOfBirth" ValidatesOnDataErrors="True" ValidatesOnExceptions="True" />
</TextBox>