How does UpdateControls support data binding?

Developer
Nov 10, 2011 at 12:02 AM

At the suggestion of a couple of people at my company, I decided to try using an Infragistics XamDataGrid control instead of a ListBox or ListView. However, the grid's column autodetection decided that the columns of my object are "ClassInstance", "WrappedObject", "Dispatcher", "Error" and "Item", which you might recognize as all the public properties of ObjectInstance. The rows are all blank. When running in a debugger, InvalidOperationException (Sequence contains no matching element) is thrown repeatedly with a call stack of

UpdateControls.XAML.Wrapper.ObjectInstance<...>.LookupProperty()
UpdateControls.XAML.Wrapper.ClassProperty.GetObjectProperty()
UpdateControls.XAML.Wrapper.ClassProperty.GetValue()
Infragistics.Windows.DataPresenter.DataRecord.GetCellValueHelper()
...

Attempting to explicitly choose fields to display using <igDP:Field> in XAML doesn't work either.

Of course, I can't expect you to debug my problem with a 3rd-party library, but this kind of call stack also occurs (without errors) in normal WPF binding. So I'm curious how data binding works normally. I mean, ForView.Wrap returns an ObjectInstance<T>, but ObjectInstance does not directly contain the properties of T, nor do I see any system-defined interface (except INotifyPropertyChanged) that might give the WPF binding system access to the wrapped object. So how does WPF figure out how to access properties of the wrapped object? How does it know to call UC's ClassProperty.GetValue?

Coordinator
Nov 10, 2011 at 2:46 PM
Edited Nov 10, 2011 at 2:47 PM

Each of the platforms does this differently. In WPF, Paul Stovell showed me how to use TypePropertyDescriptor. This is an attribute that intercepts all of the data binding requests. In Silverlight 3 and 4, it creates a DependencyProperty for each property of the wrapped view model. And in Silverlight 5 (to be released soon), is uses ICustomTypeProvider to do the interception.

If you find that the wrapper gets in the way, you can use ViewModelBase. Details at http://updatecontrols.net/doc/tips/viewmodelbase.

Developer
Nov 10, 2011 at 7:17 PM
Edited Nov 10, 2011 at 7:27 PM

I can't find TypePropertyDescriptor in the source code. Did you mean TypeDescriptionProvider? I wonder why my name is lowercase now.

Don't you love the documentation?

TypeDescriptionProviderAttribute: Specifies the custom type description provider for a class. This class cannot be inherited.

TypeDescriptionProvider: Provides supplemental metadata to the TypeDescriptor. 

Coordinator
Nov 10, 2011 at 7:29 PM

Yes, that's the one. Can't tell you what happened to your Q.