【问题标题】:Could someone tell me how do I remove an item from the ItemsGrouped collection?有人可以告诉我如何从 ItemsGrouped 集合中删除一个项目吗?
【发布时间】:2017-04-20 12:41:12
【问题描述】:

在正常的收藏中,我会使用 CollectionName.Remove(item);

但是在与<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);
            }
        }

【问题讨论】:

标签: c# xamarin xamarin.ios xamarin.android xamarin.forms


【解决方案1】:

我不会删除分组集合中的项目,而是删除分组源中的项目。

您已经拥有原始集合Devices 的副本,删除那里的项目并重新进行分组。

【讨论】:

  • 朋友您好,我按照您的建议解决了问题,非常感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-16
  • 2011-01-17
  • 1970-01-01
  • 2015-04-15
  • 1970-01-01
相关资源
最近更新 更多