【问题标题】:Update item in BindableCollection with notify ICollectionView使用 notify ICollectionView 更新 BindableCollection 中的项目
【发布时间】:2011-02-14 12:06:03
【问题描述】:

您好,我在视图中的 ListBox 控件上绑定了来自 Caliburn Micro 的集合。就是这样。

public BindableCollection<UserInfo> Friends
{
    get { return _friends; }
    set
    {
        _friends = value;
        NotifyOfPropertyChange(() => Friends);
    }
}

ListBox items 是 UserInfo 的类型。

您好,我对列表框项目进行排序和分组,为此我使用 CollectioView。

当我初始化 ListBox 时,我使用此方法对项目进行排序和分组。

private ICollectionView _currentView;

//...

private void SortContactList()
{
    _currentView = CollectionViewSource.GetDefaultView(Friends);

    _currentView.GroupDescriptions.Add(new PropertyGroupDescription("TextStatus"));

    _currentView.SortDescriptions.Add(new SortDescription("TextStatus", ListSortDirection.Ascending));

    _currentView.SortDescriptions.Add(new SortDescription("Nick", ListSortDirection.Ascending));
}

TextStatus 和 Nick 是 userInfo 类的属性。

当我更新可绑定集合 Friend 中项目的值时,我想知道如何通知集合视图有关此更改的方法。因为我需要将项目移动到正确/好组。

例如

Friend[0].TextStatus = "Ofline" -> is in offline group

我在网上改变价值;

Friend[0].TextStatus="Online" -> move in online group

在这里我想通知收藏视图 (_currentView) 关于好友收藏的更改。

【问题讨论】:

    标签: wpf listbox caliburn notify icollectionview


    【解决方案1】:

    当我创建一个包含 Rating 列的表的应用程序时,我遇到了同样的问题。 我想知道为什么我更改评分时行不上移,最后我使用了Refresh 方法。

    你的例子:

    Friend[0].TextStatus="Online" -> move in online group
    _currentView.Refresh();
    

    还好没有出现性能问题,所以现在我在类似情况下使用这个方案。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多