问题标签 [icollectionview]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
94 浏览

wpf - CollectionView not populated?

I've used ICollectionView a few times and never had any problems... but I can't get this one to work.

In my constructor I do the following:

The one thing that I think is different is that I populate my _viewModels with a separate call. So with a button for example after the app loads. Even if I call MyCollectionView.Refresh() though at that time, and _viewModels has objects in it, MyCollectionView is still empty.

Should this work? If so what am I missing and what can I look for?

0 投票
0 回答
39 浏览

wpf - 如何判断底层 ICollectionView 是否真的脏

我一直在构建一个 wpf 用户控件来充当数据导航器,用于各种表单。它将来自视图模型的底层 ICollectionView 作为数据源,就像网格等表单上的其他控件一样。网格上的视图是这样设置的;

一个典型的形式可能是这样的:

在此处输入图像描述

现在我想做的是确定底层视图集合何时变脏,以便我可以使用该信息来启用禁用导航器控件上的保存按钮等功能。我已经尝试过 CurrentChanging 和 CollectionChanged。我认为前者是两者中更有希望的,虽然当我在网格上选择或创建新行时它会触发,但当我更改单元格中的内容时它不会触发。在启用保存按钮之前,我想知道一行或多行实际上是脏的。

谢谢

0 投票
2 回答
4211 浏览

c# - Sorting ObservableCollection with ICollectionView does't work correctly

To generate the bug, select any item in TopDataGrid. As a result, the collection of items will be loaded into BottomDataGrid. This collection is sorted by Name property as I specified! Then select any other item in the TopDataGrid. The result is that ItemsSource of BottomDataGrid will be reloaded. And now the collection is unsorted! The collection looks as I specified it in code. Moreover, if I check _customerView with the debugger I see the sorted collection.

I know I can use List with OrderBy and INotifyPropertyChanged to explicitly command the UI to update itself instead of ObservableCollection and ICollectionView. But I think this is not the proper approach.

Win 7, .Net 4.0. Just copy and paste.

code

UPDATE

It seems like in ClearSortDescriptionsOnItemsSourceChange method sorting is cleared and not respecify again. I think this is the matter.

0 投票
1 回答
509 浏览

c# - Can I pass a filtered CollectionViewSource to a method?

I create a public CollectionView (cvs) and bind that to my ListView Control in a WPF application. Then there are a series of filters that add in delegates to filter my cvs object. Everything works fine in this aspect of the program.

What I'm trying to do is create Excel files of the items in my list. I can send the entire collection (TLIST) to an OpenXML function and create my files just fine. Where I'm struggling is I want to only send the filtered items into the function and figure I need to somehow send the filtered cvs.

In short, what I'm trying to get is --> cvs.ToList() but this is not a valid operation. and getting the error

"Unable to cast object of type 'System.Windows.Data.ListCollectionView' to type 'System.Collections.Generic.List`1"

Anything glaringly obvious that I'm doing wrong? Any guidance is appreciated.

Note: Even when I inspect cvs it shows all the items not just the filtered ones.

0 投票
1 回答
320 浏览

c# - ICollectionView 当前位置为 -1

我有一个ICollectionView来自一个ObservableCollection

mySpreadOrderCollection不为空,可以看出SourceCollection计数为 1

ICollectionView 观看

但是为什么CurrentPosition-1,我认为正因为如此,DataGrid 即使我已经绑定WorkingSpreadOrderCollevtionView到它,也没有显示任何东西ItemSourcce

我可以知道这里可能的错误是什么吗?

==================================================== ========

编辑:xaml binding如下,DataContext很确定是正确的,因为public同一属性中的另一个属性正确ViewModel绑定到同一属性xaml

另外,我可以Columns在数据网格中看到自动生成的,但我只是看不到记录。

====================================================

更新:我发现了愚蠢的错误。我已经调用GetDefaultView了两次,并认为创建了两个不同的视图副本,因此在“两个”副本上应用了两个过滤器。第二个过滤器阻止记录显示在DataGrid. 我现在所做的是创建一个新视图,如下所示,

0 投票
0 回答
173 浏览

wpf - 与 ViewModel、Model 和 CollectionView 的设计混淆

这个问题与设计帮助有关。在其中我提出了一个问题,我想到的一些解决方案,以及我对解决方案的看法;最后一个我认为是正确的解决方案。我正在寻求对我的解决方案的验证或挑战。对不起,很长的帖子。

我有一个ConfigActivityGroup班级(模型)。它代表一组活动。一个用户可以有很多ActivityGroups,每个都包含组的名称和多个活动,这些活动是字符串。

我有一个ConfigActivityGroupVM提供 CRUD 的命令ConfigActivityGroups

ConfigActivityGroupVMConfigActivityGroups. _ ConfigActivityGroupVMCollectionViewSource为 ObservableList<ConfigActivityGroup> 保留一个并提供一个供ICollectionViewUI 访问。

我还没有完成 UI,但我计划ICollectionViewSource绑定到一个列表,用户可以从中单击一个项目;并看到一个带有 GroupName 的文本框,以及与第一个列表相邻的另一个Activities列表ActivityGroup

这一切都很好,因为我有一个ConfigActivityGroupICollectionView. 我可以使用 currentConfigActivityGroup绑定到第二个 UI 列表以Activities在 current中显示ConfigActivityGroup

问题: 当我想为CRUD当前的活动构建命令时ConfigActivityGroup

如果ActivitiesConfigActivityGroupa 中List<string>并且我将它们直接绑定到 UI,那么我没有可以在 UI 中绑定到的“当前”活动的概念,以便我可以DeleteCurrentActivityCommand在 VM 中使用命令删除当前活动对于当前命令。

我的第一个解决方案是,在 VM 中选择 aConfigActivityGroup后(通过 ICollectionView),将所选活动中的活动复制ConfigActivityGroup到 VM 中的新活动ObservableCollection<string>中(这又具有它自己的ViewSourceand ICollectionView)。然后,我可以让 UI 第二个列表绑定到当前活动的 ICollectionView ConfigActivityGroup。因此,我的命令将修改活动的 ICollectionView。但是,当我尝试为当前的新活动创建一个新活动时遇到了障碍,ConfigActivityGroup我无法将活动设置ICollectionView.CurrentItem为不同的活动字符串(因为它是只读的)。

我认为一个解决方案是在一个ActivityString类中将活动字符串装箱有一个字符串。总的来说,我对这种方法不太满意。

我认为的第二个解决方案是使List<string>inConfigActivityGroup成为ObservableCollection<string>. 这将简化虚拟机。我犹豫使用这种方法,因为模型是通过魔术(MyCouch + CouchDB)从非UI线程从数据库加载的json-deserialisation,然后当ObservableCollection从与其创建线程不同的线程访问时出现问题(我认为,来自内存) . 我认为使用许多线程安全的 ObservableCollections 之一是矫枉过正的。

第三个解决方案我在写这个问题时想是把List<string>活动的模型保留在ConfigActivityGroup. 然后,在其ConfigActivityGroup中选择a时,以活动的 直接作为源来ICollectionView初始化 a 。这样,UI 可以直接绑定到活动,并且 UI 可以负责编辑实际的活动字符串;并且当前选择的活动的概念仍然存在,然后我可以使用命令将其删除。CollectionViewSource/ICollectionList<string>

认为第三种方法是正确的方法,但我愿意听取社区的想法。这是我第一次使用 MVVM,我试图保持职责分离并尽可能多地使用命令。

额外数据:

  • 一旦 ConfigActivityGroup 从数据库加载并放入 VM 中,除了 VM 本身之外的任何人都不会通过 UI 更改它。
0 投票
0 回答
475 浏览

c# - 无法访问 CollectionViewSource.GetDefaultView 和 ICollectionView.Filter

您好我正在尝试使用 CollectionViewSource 和 ICollectionView 过滤列表框,但我无法访问它们。该定义没有上述属性。知道为什么吗?我正在开发一个基于 Windows 的通用应用程序。

我的目标是根据文本框中输入的文本过滤列表框。

提前谢谢你的帮助

XAML

XAML.cs

CollectionViewSource 的元数据

0 投票
1 回答
611 浏览

c# - 在 ICollectionView 中过滤对象的子项

我有一个名为 ItemType 的对象的集合,每个对象都有一个 Item 的子集合。顶级集合被包装到 ObservableCollection 中,因此当用户从集合中添加或删除内容时它会做出响应。这绑定到 TreeView,以便每个 ItemType 在下面显示其子项。

我想要做的是使用过滤器来摆脱设置为删除的子项目对象。我很挣扎,因为 Filter 需要一个布尔谓词,当然,只有顶级 ItemType 被传入。例如:

不好,因为它正在删除 ItemType,而不是下面的任何 Items。

我试过这样做:

但这最终实际上是从底层集合中删除项目,而不是执行实际的过滤器。

有什么办法可以过滤子集合吗?

0 投票
1 回答
535 浏览

wpf - 将新项目添加到其内部 ObservableCollection 时如何刷新 ICollectionView

请在下面查看我的代码

我想知道如何在将新项目插入 TestList 或重新分配整个 TestList 时更新 PersonListView 并刷新 UI?我试过在TestList set 方法中调用Refresh 方法,但是当一个新项目插入到集合中时,不会调用set 方法。

谢谢

0 投票
1 回答
298 浏览

c# - Filter Criteria OR Instead of AND C# WPF

I am currently filtering a DataGrid based on the selection of a group of CheckBoxes. Criteria are added to a list of Criteria and the ICollectionView that the DataGrid is bound to is filtered appropriately.

This works OK if I want to filter on an 'AND' basis. Each job has an employee associated to it, but at the moment the filter works by saying show jobs where job.employee = employee 1 AND job.employee = employee2. This is the code at the moment, it will filter like so;

This is currently filtering by jobs where ITName = tag1 AND ITName = tag2etc. etc. A job will never have more than one employee assigned to it, so inevitably as soon as the user clicks on more than one CheckBox no jobs are shown.

How can I change my filter so that instead it filters on an 'OR' basis? For example show jobs where job.employee = employee 1 OR job.employee = employee 2