WPF Binding to Proxy

2.9k views Asked by At

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?

2

There are 2 answers

1
Stephen Cleary On BEST ANSWER

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.

0
sellmeadog On

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