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);
}
}
也許這個http://stackoverflow.com/questions/9743420/remove-an-item-from-an-observablecollection-in-a-collectionchanged-event-handler答案可以幫助你。 –
你好我的朋友,非常感謝你的幫助! – user2530802