Silverlight: set DateTime property via XAML?
I have a class with DateTime field:
public class TimelineObject : FrameworkElement
{
private DateTime date;
public DateTime Date
{
get { return date; }
set { date = value; }
}
}
When I try to set a date in XAML like this
<TimelineObject Date="3/1/2011"/>
I am getting 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?
+3
source to share
1 answer
Try to create a TypeConverter for DateTime that converts DateTime to / from string values and sets it using TypeConverterAtrribute on your Date property. Be careful, it is best to use InvariantCulture in a custom TypeConverter. In other cases, you will still have problems with client machines that may be using different culture settings.
+3
source to share