Hello, I got a DatePicker on my Edit/Create item page and the page is crashing everytime I open it.
I've got a model that has a Date on string type and I want to show it as a DatePicker. Also when I'm editing an object I want to be able to edit it by picking a DateTime on my DatePicker and convert it to string .
I've made already the Converter Class:
public class DateTimeToStringConverter : IValueConverter
{
public object Convert (object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var s = value as string;
if (s == null) {
throw new NotImplementedException ();
}
else {
DateTime myDate = DateTime.ParseExact (s, "dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture);
return myDate;
}
}
public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var s = (DateTime)value;
if (s == null) {
throw new NotImplementedException ();
}
else {
string ret = s.Date.ToString ();
return ret;
}
}
}
And this is the way I set the binding to the button:
var dateLabel = new Label { Text = "Date" };
var dateEntry = new DatePicker ();
dateEntry.SetBinding (Entry.TextProperty, new Binding ("Date", BindingMode.TwoWay, new DateTimeToStringConverter (), null));
For some reason its crashing my application when I try to open that page. Anyone could give me an help ?
Thanks in advance