2017-04-22 112 views
1

我試圖通過保存在裏面的日期來過濾observablecollection。用戶將通過使用日曆視圖選擇日期。任務<ObservableCollection <AppointmentItem >>不包含的定義其中

public async Task RefreshItems(bool showActivityIndicator, bool syncItems) 
     { 
      using (var scope = new ActivityIndicatorScope(syncIndicator, showActivityIndicator)) 
      { 

       var items = manager.GetAppointmentItemsAsync(); 


       CalendarVM vm = new CalendarVM(); 
       calendar.SetBinding(Calendar.DateCommandProperty, nameof(vm.DateChosen)); 
       calendar.SetBinding(Calendar.SelectedDateProperty, nameof(vm.DateSelected)); 
       calendar.BindingContext = vm; 

       var filtered = items.Where(appointmentItem => appointmentItem.Date == SelectedDate); 
      } 
     } 

這是AppointmentPage類中用戶選擇日期和數據的代碼。

public async Task<ObservableCollection<AppointmentItem>> GetAppointmentItemsAsync(bool syncItems = false) 
     { 


      try 
      { 

       IEnumerable<AppointmentItem> items = await appointmentTable 
             .ToEnumerableAsync(); 

       return new ObservableCollection<AppointmentItem>(items); 

      } 
      catch (MobileServiceInvalidOperationException msioe) 
      { 
       Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message); 
      } 
      catch (Exception e) 
      { 
       Debug.WriteLine(@"Sync error: {0}", e.Message); 
      } 
      return null; 

     } 

這裏是dataManger類的代碼,用於從數據庫中檢索數據。

目前我得到這個錯誤:

Error CS1061 'Task>' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'Task>' could be found (are you missing a using directive or an assembly reference?

回答

1

我試圖改變

var items = manager.GetAppointmentItemsAsync(); 

ObservableCollection<AppointmentItem> items = await manager.GetAppointmentItemsAsync(); 

,那麼你可以嘗試添加

using System.Linq; 
+1

我也愛你:D –

+0

@glenncooper該死的!我已經回答了太多這樣的問題,沒有人告訴我他們愛我...感覺嫉妒 – CodingYoshi

2

你的代碼下面一行:

var items = manager.GetAppointmentItemsAsync(); 

返回Task這顯然不包含Where,這就是爲什麼你會得到一個錯誤。

請該行更改爲:

var items = await manager.GetAppointmentItemsAsync(); 

,然後你會得到ObservableCollection<AppointmentItem>類型的集合裏面應該有Where成員。

+0

我非常愛你。 –

+1

'':) #WishStackOverflowAllowedSmallerComments。順便說一句,給@Alessandro Caliaro一些愛:D。他是第一個回答這個問題的人。 –

相關問題