【发布时间】:2017-06-17 04:03:09
【问题描述】:
我在包含 datetime 属性的共享 PCL(适用于 android 和 uwp 应用程序)中有模型类:
public class Meter {
public int meter_value {get; set; }
public DateTime meter_start { get; set; }
public DateTime meter_end { get; set; }
... other int and string properties
}
在 MainPage.cs 我有
public Meter _meter;
public MainPage()
{
this.InitializeComponent();
_meter = new Meter();
}
我正在尝试使用以下代码将此绑定到 xaml 控件:
<TextBox
Text="{x:Bind _meter.meter_value, Mode=TwoWay}">
<CalendarDatePicker
Name="meter_start"
Date="{x:Bind _meter.meter_start, Mode=TwoWay}"
DateFormat="{}{day.integer}/{month.integer}/{year.full}" >
</CalendarDatePicker>
此代码产生编译时错误:Invalid binding path '_meter.meter_start' : Cannot bind type 'System.DateTime' to 'System.Nullable(System.DateTimeOffset)' without a converter
当我将 x:Bind 更改为 Binding 时,应用程序编译,但我的模型中的meter_start 属性值为 0001/01/01。
有人可以帮我解决这个问题吗?
【问题讨论】:
标签: c# xaml uwp uwp-xaml xamarin.uwp