Bind it tight

Data-binding has become one of the central ideas amongst modern GUI frameworks. It has enabled the use of view models, a set of objects representing the GUI state which can be linked to the actual GUI elements in a very code free way. This means that once you have tested your view model, you can be confident that the GUI is showing the right information.

In the pre-WinRT days, the data binding was all implemented in managed code, in the same language as the code which controlled the GUI. In the WinRT world however, we need to be able to bind across languages and components (in the C++ case). There’s an interesting post here which looks at optimisations that the .NET WinRT wrapper provides to make this more efficient. For C++ there needs to be a way for the code implementing the binding to get hold of the metadata about the properties. This is implemented by having the compiler generate a class which can provide this information at runtime. In the C# CLR case we have Reflection, so it is possible for the compiler to avoid doing this, without all this code generation.

The original post doesn’t really give a clear guide as how the external code gets hold of the type information. So I got out my copy of .NET Reflector, set the system up for debugging by globally setting the COMPLUS_ZAPDISABLE environment variable, and placed an mscorlib.ini file next to mscorlib.dll to stop it being optimised too much.

We can now breakpoint the code to watch the creation of the object which supports the ICustomProperty interface, which is exported via normal CLR COM interop back to the WinRT framework.

property

Using Reflector is easy to look at the WinRT support that has been included into the framework, which includes a lot of type that marshal between the WinRT types like IVector and IIterable and their CLR counterparts.

winrtsupportwinrtsupport2winrtsupport3

Lots of this code is quite low level and quite interesting to read, and lots of it sits on top of the existing .NET COM interop layer with its RCW and CCW wrappers.

Shawn Farkas has a nice MSDN magazine article that talks about this interop and how it works.

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s