2017-04-20 42 views
0

在一個正常的收藏我會使用CollectionName.Remove(item);有人能告訴我如何從ItemsGrouped集合中刪除項目嗎?

但在這收集<Grouping <string, Device>我不明白如何做到這一點。我需要刪除該項目來更新我的ListView。

歡迎所有幫助,謝謝!

視圖模型:

構造:

var sorted = from item in Devices 
         orderby item.Grupo 
         group item by item.Grupo.ToString() into itemGroup 
         select new Grouping<string, Device>(itemGroup.Key, itemGroup); 

      ItemsGrouped = new ObservableCollection<Grouping<string, Device>>(sorted); 
public ObservableCollection<Device> Devices 
{ 
    get { return _devices; } 
    set 
    { 
     _devices = value; 
     OnPropertyChanged(); 
    } 
} 

public ObservableCollection<Grouping<string, Device>> ItemsGrouped { get; set; } 




public class Device:ViewModelBase 
     { 
      public int ID { get; set; } 

      public string Title { get; set; } 
      public string Description { get; set; } 
      public string Image { get; set; } 
      public string Grupo { get; set; } 
     } 



public class Grouping<K, T> : ObservableCollection<T> 
     { 
      public K Key { get; private set; } 

      public Grouping(K key, IEnumerable<T> items) 
      { 
       Key = key; 
       foreach (var item in items) 
        this.Items.Add(item); 
      } 
     } 
+0

也許這個http://stackoverflow.com/questions/9743420/remove-an-item-from-an-observablecollection-in-a-collectionchanged-event-handler答案可以幫助你。 –

+0

你好我的朋友,非常感謝你的幫助! – user2530802

回答

1

我不會分組集合中,但相反在分組的源中刪除的項目。

您已有原始集合Devices的副本,請將其刪除並重新進行分組。

+0

你好我的朋友,我遵循你的建議並解決了問題,非常感謝你的幫助! – user2530802

相關問題