ListView项目似乎没有正确投射

时间:2018-01-14 04:44:04

标签: c# xaml listview datetime xamarin.forms

我有Xamarin.Forms XAML ListView来自键入的ItemSource

ObservableCollection<WorkOrderActivity> serviceList = 
  new ObservableCollection<WorkOrderActivity>();
servicelistview.ItemsSource = serviceList;

这是我的表:

public class WorkOrderActivity
{

    string id;
    int workordernumber;
    string activity;
    string service;
    string activitylocation;
    float actualquantity;
    string reference;
    DateTime arrivaltime;
    DateTime departuretime;
    string remarks;
    bool complete;
    bool done;
    string uom;
    int startgauge;
    int endgauge;
    int contactgauge;

    [JsonProperty(PropertyName = "id")]
    public string Id
    {
        get { return id; }
        set { id = value; }
    }

    [JsonProperty(PropertyName = "workordernumber")]
    public int WorkOrderNumber
    {
        get { return workordernumber; }
        set { workordernumber = value; }
    }

    [JsonProperty(PropertyName = "activity")]
    public string Activity
    {
        get { return activity; }
        set { activity = value; }
    }

    [JsonProperty(PropertyName = "service")]
    public string Service
    {
        get { return service; }
        set { service = value; }
    }


    [JsonProperty(PropertyName = "arrivaltime" )]
    public DateTime ArrivalTime
    {
        get { return arrivaltime; }
        set { arrivaltime = value; }
    }

    [JsonProperty(PropertyName = "departuretime")]
    public DateTime DepartureTime
    {
        get { return departuretime; }
        set { departuretime = value; }
    }

    [JsonProperty(PropertyName = "activitylocation")]
    public string ActivityLocation
    {
        get { return activitylocation; }
        set { activitylocation = value; }
    }

    [JsonProperty(PropertyName = "actualquantity")]
    public float ActualQuantity
    {
        get { return actualquantity; }
        set { actualquantity = value; }
    }

    [JsonProperty(PropertyName = "startgauge")]
    public int StartGauge
    {
        get { return startgauge; }
        set { startgauge = value; }
    }

    [JsonProperty(PropertyName = "endgauge")]
    public int EndGauge
    {
        get { return endgauge; }
        set { endgauge = value; }
    }

    [JsonProperty(PropertyName = "contactgauge")]
    public int ContactGauge
    {
        get { return contactgauge; }
        set { contactgauge = value; }
    }

    [JsonProperty(PropertyName = "reference")]
    public string Reference
    {
        get { return reference; }
        set { reference = value; }
    }

    [JsonProperty(PropertyName = "remarks")]
    public string Remarks
    {
        get { return remarks; }
        set { remarks = value; }
    }

    [JsonProperty(PropertyName = "uom")]
    public string UOM
    {
        get { return uom; }
        set { uom = value; }
    }

    [JsonProperty(PropertyName = "done")]
    public bool Done
    {
        get { return done; }
        set { done = value; }
    }

    [JsonProperty(PropertyName = "complete")]
    public bool Complete
    {
        get { return complete; }
        set { complete = value; }
    }

    [Version]
    public string Version { get; set; }
    [CreatedAt]
    public DateTimeOffset CreatedAt { get; set; }
    [UpdatedAt]
    public DateTimeOffset UpdatedAt { get; set; }
    [Deleted]
    public bool Deleted { get; set; }
}

当我从列表视图中选择一个项目时出现问题,我得到正确的记录,但是日期时间字段只有日期,时间为零。

private void servicelistview_ItemTapped(object sender, ItemTappedEventArgs e)
{
   var p = (WorkOrderActivity)e.Item;

当我在列表视图中显示记录时,它会显示正确的时间和日期,当我将所选项目转换为WorkOrderActivity时,它就会出现。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

DateTime.Date返回00:00:00;来自DateTime.Date文档:

// Returns:
//     A new object with the same date as this instance, and the time value set to 12:00:00
//     midnight (00:00:00).

示例:

var dt = new DateTime(2018, 01, 14, 1, 2, 3);
Debug.WriteLine(dt.Date);
Debug.WriteLine(dt.Hour + " " + dt.Minute + " " + dt.Second);

输出:

1/14/2018 12:00:00 AM
1 2 3
相关问题