I'm binding a standard DatePicker to a property in my codebehind like so:
XAML:
<DatePicker Text="{Binding Start, Mode=TwoWay}" Width="150" BorderBrush="LightGray" VerticalAlignment="Center" Margin="3"/>
Code:
public DateTime Start
{
get { return _start; }
set
{
_start = value;
RaisePropertyChangedEvent("Start");
}
}
In the constructor I initialize the value to DateTime.Now, which today is January 8th. 2014 (that should unambigous across different languages). However I'm on a danish machine so the string formatted value will be 8/1/2014 as opposed to the US style 1/8/2014.
The first problem is that the date picker shows the value formatted as US style, and when I open the drop down, it also says August 1st.
The second problem is worse though. When I select e.g. December 1st from the drop down, the text says 12/1/2014, which is correct in US style, but the actual datetime selected (on the property) is the 12th of January, which matces the Danish style...
I'm guessing it's because of some issue in converting to/from localized string representations of a DateTime, but why is the date picker ignoring localization? And how can I fix it?