Xamarin刷新后坏了ItemSource

时间:2019-01-27 14:32:18

标签: listview xamarin xamarin.forms

在数据存储区的构造函数中,我检查当前日期,如果它是星期日,则从12:00到18:00填充ItemSource,如果不是,则从9:00到18:00填充,但即使它是星期日和我,刷新我的ListView,从9:00开始填充它。

构造函数:

 items = new List<Termin>();


        if (TomorrowPage.camefromtomorrow == true)
        {
            thedate = DateTime.Now.AddDays(1).DayOfWeek.ToString();
        }

       else if (SelectedDateList.camefromdate == true)
        {
            thedate = CalendarPage.selection.DayOfWeek.ToString();
        }

      else  if (ItemsPage.camefromtoday == true)
        {
            thedate = DateTime.Now.DayOfWeek.ToString();
        }


  if (thedate.Equals("Sunday"))
  { 
     itssunday = true; 
  }
  else
  { 
     itssunday= false;
  }

  if (itssunday)
  {
      for (int i = 12; i <= 18;i++)
      {
           items.Add(new Termin { Id = Guid.NewGuid().ToString(), Text = "" + i + ":00", Description = "" });        
      }
  } else ...

刷新任务:

 public async Task<IEnumerable<Termin>> GetItemsAsync(bool forceRefresh = false)
        {

            return await Task.FromResult(items);
        }

我需要在哪里再次检查星期几?

模型如下:

     async Task ExecuteLoadItemsCommand()
    {
        if (IsBusy)
            return;

        IsBusy = true;
        try
        {
            Items.Clear();
            var items = await DataStore.GetItemsAsync(true);
            foreach (var item in items)
            {
                Items.Add(item);

            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        finally
        {
            IsBusy = false;
        }
    }

发现了问题

解决方案:

在填充LV后,我将false分配给明天,因此我的应用程序认为第二天会出现这种情况。

1 个答案:

答案 0 :(得分:0)

在填充LV后,我将false分配给明天,因此我的应用程序认为第二天会出现这种情况。

 TomorrowPage.camefromtomorrow = false;
 SelectedDateList.camefromdate = false;

 reservations = await CheckReservations(currentDate);

更改顺序,现在可以使用了。