In a normal colletion I would use CollectionName.Remove(item);
But in this colletion with <Grouping <string, Device>
I do not understand how to do this. I need to remove the item to update my ListView.
All help is welcome, thank you!
ViewModel:
Constructor:
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);
}
}