WPF 绑定到代理

发布于 2024-11-17 23:32:46 字数 705 浏览 6 评论 0原文

我有许多实现自己的自定义更新通知的集合类。将这些通知转换为代理类中的 INotifyCollectionChanged 实现应该非常容易。

INotifyPropertyChanged 已被处理;这个问题只是关于收集代理。

因此,我正在寻找一种从 XAML 创建相对容易使用的代理的方法。对于子集合尤其如此。自定义集合类是库的一部分,不能修改(也不能从中派生)。也不可能用 INotifyCollectionChanged 兼容的等效项替换集合类型,因为数据更新代码不在我的控制范围内。

我更喜欢一个也适用于 SL 的解决方案,但这不是一个严格的要求。

到目前为止,我相信以下方法是可行的:

  • 定义为添加 Proxy 属性的集合类注册的 TypeDescriptionProvider 。这允许将路径绑定到代理中。从 XAML 角度来看,此解决方案似乎是最简单的,但与 SL 不兼容。
  • 定义一个创建代理的值转换器。这需要 XAML 方面做更多的工作。它应该适用于 SL。然而,如果一条路径上需要多个值转换,则可能需要“中间”视觉元素来保存值转换器结果。

我研究了ObjectDataProvider,但我认为它不能在这种情况下使用(代理创建方法对于容器中的对象类型必须是通用的)。

关于这两种方法中哪一种更好或任何其他方法有什么建议吗?

I have a number of collection classes that implement their own custom update notification. It should be pretty easy to translate these notifications to an INotifyCollectionChanged implementation in a proxy class.

INotifyPropertyChanged is already taken care of; this question is just about collection proxies.

So, what I'm looking for is a way of creating the proxies that is relatively easy to use from XAML. This is particularly true for sub-collections. The custom collection classes are part of a library that cannot be modified (nor derived from). It's also not possible to replace the collection types with INotifyCollectionChanged-compatible equivalents, because the data-updating code is outside my control.

I'd prefer a solution that works with SL as well, but it's not a strict requirement.

So far, I believe the following approaches are viable:

  • Define a TypeDescriptionProvider registered for the collection classes that adds a Proxy property. This allows Binding paths to dot-into the proxy. It seems that this solution is easiest from a XAML perspective, but is not SL-compatible.
  • Define a value converter that creates the proxies. This would work with a bit more work from the XAML side. It should work for SL. However, it may require "intermediate" visual elements to hold the value converter result if more than one value conversion is necessary on a path.

I looked into ObjectDataProvider, but I don't think it can be used in this situation (the proxy creation method must be generic on the type of objects in the container).

Any recommendations on which of these two approaches is better, or any other approaches?

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

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

发布评论

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

评论(2

手心的海 2024-11-24 23:32:46

Paul Stovell 创建了一个可编辑的集合适配器,它本身可能无法满足您的需求,但它应该为您提供一个创建适当的适配器/代理的良好起点。

http://www.paulstovell.com/editable-collection-adapter

Paul Stovell created an editable collection adapter which in and of itself probably won't satisfy your needs, but it should give you a good starting point to create an appropriate adapter/proxy.

http://www.paulstovell.com/editable-collection-adapter

你的往事 2024-11-24 23:32:46

我决定继续使用也是 MarkupExtension 的类型转换器,如 此博文

Silverlight 当前不支持 MarkupExtension,但 v5 中将支持该功能。

I've decided to move forward with a type converter that is also a MarkupExtension, as described by this blog post.

MarkupExtension isn't currently supported by Silverlight, but it will be in v5.

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