Wrap VEMap items into VEPushPin to ease databinding scenarios

Mar 18, 2009 at 10:04 PM
Hi guys,

First of all, awesome job have done here, really impressive.

I have a suggestion though regarding databinding on VEMap ItemsSource. I think it would be nice to wrap the items data bound into VEPushPin much like Treeview vs treeviewItem or ScatterView vs ScatterviewItem. This way we don't have to bind to a VEPushPin collection. I have experienced it a bit and it seems pretty straightforward, the only trick is how to map VEPushPin altitude, longitude, latitude properties.

I have tested with the following changes:

* register VEPushpin's Altitude, Latitude and Longitude DPs as "Attached" DPs,
* on my data item, I bind my alt/lat/lon properties to the VEPushPin attached properties
* override VEMap's GetContainerForItemOverride  method in order to return VEPushPin as item container
* update RaiseViewChanged method on VEMap in order to call VEPushPin's UpdatePosition if the item Container is VEPushPin
    ( if ( o is VEPushPin || this.ItemContainerGenerator.ContainerFromItem(o) is VEPushPin) )
* override VEMap's PrepareContainerForItemOverride method in order to map the VEPushPin Latitude/Longitude properties to the item bound properties throught the Attached DPs:
        if (element is VEPushPin && item is DependencyObject)
                VEPushPin l_pushpin = (VEPushPin)element;
                DependencyObject l_item = (DependencyObject)item;

                l_pushpin.Latitude = (double)l_item.GetValue(VEPushPin.LatitudeProperty);
                l_pushpin.Longitude = (double)l_item.GetValue(VEPushPin.LongitudeProperty);

The last thing here is to bind the VEPushPin lat/lon properties to the item (twoway binding).

Mar 18, 2009 at 11:02 PM
That is a very good suggestion and would bring the VEMap in line with the architecture of the Treeview and ScatterView like you mentioned.

The only real reason we did do this anyway was the VEPushPin was until recently very tightly coupled to the VEMap and was actually not a ContentControl.  It acted more like TextBlock, with a Text property.  We improved the interfaces and made VEPushPin a ContentControl for this release but didn't have time to do what you suggested.

If you would like to contribute your code patch I can merge it into the codebase.

Mar 18, 2009 at 11:02 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 19, 2009 at 9:40 AM
hi joshb,

Let me polish my sample and workout a nice solution to bind the data to the vepushpin and i'll submit it to you.