Wednesday, January 25, 2012

WPF Mapping / Association Control

When importing data from one store to another, many applications allow visual "mapping" of source fields to destination fields where lines are drawn to connect the two.
I tried in vain to find some kind of WPF/Xaml control that would do that, so I created one:

The control (regular user control) would be useful for any kind of association between two sets of data. The user creates associations by dragging from source to destination. It has a mode for one-to-one (a source item can only be mapped to one destination item) and one-to-many. Moving the scroll bars of the lists redraws the association lines appropriately. It's done MVVC style with models for the control as a whole and for the lists that hold the fields.

I was amazed at how easy this was to do with Xaml. I'm only a recent Xaml user, and when I use it I'm so pleased and dismayed at the same time. Pleased because it's such a rich, well thought out technology. Dismayed because MS has been forced to essentially abandon it in favor of the tyranny of HTML. I wonder how much more difficult this same thing would be to do using HTML5.

Source code here. Hope someone else can make use of it.