【发布时间】:2019-02-27 15:09:07
【问题描述】:
在我开发的 Xamarin.Forms 项目中,我创建了一个与 DateTime 一起使用的 NullableDatePicker?价值。在 XF 3.3 之前,DatePicker 能够设置 DateTime? ViewModel 的属性为 null。这不再适用于 XF 3.5 现在,当我的平台渲染器将 XF 控件的 BindableProperty 设置为 null 时,视图模型的绑定属性不会更新。将值更改为 DateTime 有效。
搜索 XF 3.3 和当前 XF 3.5 之间的更改并没有为绑定带来任何重大更改,我希望 stackoverflow 上的人可以提供帮助。我已经搜索了很多可能导致我的问题的原因。
public class ViewModel {
private DateTime? _date;
public DateTime? Date{
get => _date;
set => SetProperty(ref _date, value);
}
}
NullableDatePicker : DatePicker {
public static readonly BindableProperty NullableDateProperty = BindableProperty.Create(nameof(NullableDate), typeof(DateTime?), typeof(NullableDatePicker), null, BindingMode.TwoWay);
public class DateTime? NullableDate
{
get { return (DateTime?)GetValue(NullableDateProperty); }
set { SetValue(NullableDateProperty, value); }
}
}
public class NullableDatePickerRenderer : DatePickerRenderer
{
...
public void OnClearDateTimeSelection(){
((IElementController) Element).SetValueFromRenderer(NullableDatePicker.NullableDateProperty, null);
...
}
}
【问题讨论】:
-
你可以提供一个最小的、完整的、可验证的例子,我帮你查。^.^
标签: c# mvvm xamarin.forms