I've added a DatePicker in own of my views, and I get an error for the Visibility property (which I have not configured).
The error is:
System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value '8/18/1993' (type 'System.String'); BindingExpression: Path='DateOfBirth' DataItem='Gui.ViewModels.RegisterPersonalViewModel' (HashCode=64515557); target element is 'Microsoft.Phone.Controls.DatePicker' (Name='DateOfBirth'); target property is 'Visibility' (type 'System.Windows.Visibility').. System.ArgumentException: Requested value '8/18/1993' was not found.
at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
at MS.Internal.SilverlightTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, CultureInfo culture, Boolean isForward)
at MS.Internal.Data.TargetDefaultValueConverter.Convert(Object o, Type type, Object parameter, CultureInfo culture)
at MS.Internal.Data.DynamicValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
at System.Windows.Data.BindingExpression.ConvertToTarget(Object value).
The view field looks like:
<toolkit:DatePicker x:Name="DateOfBirth" />
And the property in the view model:
public DateTime DateOfBirth { get; set; }
Hence I have nothing which maps the Visibility property to the field. So why do it make that binding?
I also tried to add a visibility binding like this:
<toolkit:DatePicker x:Name="DateOfBirth"
Visibility="{Binding Path=IsDateOfBirthVisible,
Converter={StaticResource BooleanToVisibilityConverter}}"/>
And add a field:
public DateTime DateOfBirth { get; set; }
public bool IsDateOfBirthVisible { get; set; }
But then I get the following exception:
An exception of type 'System.Exception' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
I've also tried to add custom conventions:
ConventionManager.AddElementConvention<DatePicker>(DateTimePickerBase.ValueProperty, "Value", "SelectedDate");
ConventionManager.AddElementConvention<DatePicker>(DateTimePickerBase.ValueStringFormatProperty, "ValueStringFormat", "ValueStringFormatChanged");
ConventionManager.AddElementConvention<DatePicker>(DateTimePickerBase.ValueStringProperty, "ValueString", "ValueStringChanged");
ConventionManager.AddElementConvention<DatePicker>(UIElement.VisibilityProperty, "Visibility", "VisibilityChanged");
But that doesn't make a difference.
I'm new both to caliburn and windows phone, so there might be a stupid mistake somewhere.
How do I get rid of that exception?
(the datepicker is from https://phone.codeplex.com/)
Caliburn.Micro has a "catch all" convention definied on the
FrameworkElement
which binds your matching property on the viewmodel to theFrameworkElement.VisibilityProperty
Because Caliburn.Micro does not know about the
Microsoft.Phone.Controls.DatePicker
type or its base classes (DateTimePickerBase
,Control
) it fallbacks to theFrameworkElement
convention and it tries to bind yourDateTime
to theDatePicker
VisibilityProperty
so you see the exception in the Output window.There are two solutions:
<toolkit:DatePicker Value="{Bidning DateOfBirth}" />
Create a custom convention, which is in this case:
Note: you can only have one convetion for a given type, so this should be your only
AddElementConvention<DatePicker>
call.