通常のcolletionでは、私はCollectionName.Remove(item);を使用します。誰かが私にItemsGroupedコレクションからアイテムを削除する方法を教えてもらえますか?
しかし、<Grouping <string, Device>
とこのcolletionでは、私はこれを行う方法を理解していません。リストビューを更新するにはアイテムを削除する必要があります。
すべての援助を歓迎します。ありがとうございます!
のViewModel:
コンストラクタ:
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