I have a class with a DateTime field:
public class TimelineObject : FrameworkElement
{
private DateTime date;
public DateTime Date
{
get { return date; }
set { date = value; }
}
}
When I try to set the date in XAML like this
<TimelineObject Date="3/1/2011"/>
I get an XAMLParseException:
Failed to create a 'System.DateTime' from the text '3/1/2011'.
As far as I can see, the format of the string is correct (ShortDatePattern, as described here). What am I doing wrong?
Try to create TypeConverter for DateTime type which converts DateTime to/from string values and specify it with TypeConverterAtrribute for your Date property.
Be carefull, best of all use InvariantCulture in the custom TypeConverter. In other case you still will have problems on client machines which might use different culture settings.