订阅集合中的集合的良好 Rx 方式

发布于 2024-11-16 10:40:49 字数 514 浏览 2 评论 0原文

我将描述我的对象模型,然后描述我想要做什么。

它是一个 Silverlight 应用程序,这些是绑定到 UI 元素的模型对象。

一个Agreement有一个TradingBranch的集合,可以添加或删除分支。一个分支有产品集合。

agreement.Branches
         .SelectMany(x => x.Products)
         .Distinct()

这些系列由分支和产品矩阵驱动。相同的产品可以被多个分支选择,因此是不同的。

本质上,我想让用户从已选择可用于任何分支的所有产品的列表中进行选择。我希望当矩阵发生变化时更新此列表。

因此,不必为分支添加 CollectionChanged 处理程序,然后使用更多处理程序来侦听 Products 集合,确定产品是否已经存在,然后在删除分支时取消订阅等,我希望有一些不错的我可以使用 Rx 语法简单地说 - “听这一段 LINQ”,并在更改时更新我将 ListBox 绑定到的其他可观察集合。

I'll describe my object model, then what I want to do.

It is a Silverlight application, and these are model objects that are bound to UI elements.

An Agreement has a collection of TradingBranch, branches can be added or removed. A branch has collection of Product.

agreement.Branches
         .SelectMany(x => x.Products)
         .Distinct()

These collections are driven by a matrix of branches and products. The same products can be selected by more than one branch, hence the Distinct.

Essentially I want to let the user select from a list of all the products that have been selected as available for any of the branches. I want this list to be updated when there is a change in the matrix.

So rather than having to add a CollectionChanged handler for the branches, then more handlers to listen on the Products collection, work out whether the product is already there and then have to unsubscribe when branches are removed etc etc, I was hoping there was some nice Rx syntax I could employ to say simply - "listen to this piece of LINQ" and update this other observable collection that I'm binding my ListBox to when it changes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓦然回首 2024-11-23 10:40:49

尽管名称相似,IObservable 和 ObservableCollection 完全不相关,而且不幸的是也不兼容。他们有两种截然不同的观察收藏的模型。

查看可绑定 LINQ。它尝试定义 LINQ-to-ObservableCollection,以便对 ObservableCollection 进行 LINQ 查询再次生成 ObservableCollection。不过,该项目似乎已经死了,而且我还没有使用推荐的替代品(Obtics)。

Despite the name similarities, IObservable and ObservableCollection are completely unrelated and unfortunately also incompatible. They have two very different models of observing a collection.

Have a look at Bindable LINQ. It attempts to define LINQ-to-ObservableCollection, such that a LINQ query on a ObservableCollection results in a ObservableCollection again. The project seems dead, though, and I haven't used the recommend replacement yet (Obtics).

つ可否回来 2024-11-23 10:40:49

尝试我的 ObservableComputations 库:

agreement.Branches
         .SelectingMany(x => x.Products)
         .Distincting()

agreement.BranchesProducts 的类型应为 INotifyCollectionChanged (ObservableCollection)。

Try my ObservableComputations library:

agreement.Branches
         .SelectingMany(x => x.Products)
         .Distincting()

agreement.Branches and Products should be of type INotifyCollectionChanged (ObservableCollection).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文