I have a TextBox in WPF binded to a DateTime property. Whenever a user enter a date in that TextBox, i need the binded DateTime property to read the date in dd-MM-yyyy format.
i.e when the user enter 05-04-2015, the binded DateTime Property should get DateTime value corresponding to 5th April 2015.
I did a normal binding but the property is interpreting the date as 4th May 2015 instead of 5th April 2015.
In View:
<TextBox Grid.Row="1" Grid.Column="1" Style="{StaticResource TextBoxStyle}"
Text="{Binding NewStaff.Insurance.ExpiryDate}"></TextBox>
In viewmodel I have a NewStaff property which refer to a Staff class instance, this staff class has a insurance class instance. Inside Insurance class I have a DateTime Property called ExpiryDate.
class Staff{
public ICard Insurance{get;set;}
public Staff(){
Insurance = new Insurance();
}
}
class Insurance:ICard
{
/// <summary>
/// Expiry date of insurance card.
/// </summary>
public DateTime ExpiryDate
{
get;
set;
}
}
Now when I type 05-04-2015 in the textbox, the binded ExpiryDate property is interpreting the date as 4th May 2015. Whereas I need ExpiryDate to interpret it as 5th April 2015.