2

Resolved

Wrap VEMap items into VEPushPin to ease databinding scenarios

description

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).

file attachments

comments

aguerot wrote Mar 19, 2009 at 7:56 PM

I have played a bit with the data binding and it seems that adding a new item to the data source takes quite some time to be reflected on the UI (a few seconds), is this something that you're experiencing as well?

aguerot wrote Mar 22, 2009 at 2:54 PM

Hi Joshb,

Here is the solution I came up with in relation to databinding. As mentioned earlier, the items data bound are now wrapped into VEPushPin objects similarly to what's done on Treeviews or ScatterViews. This is acheived by overriding 2 methods on VEMap: GetContainerForItemOverride and IsItemItsOwnContainerOverride.

I decided not to use attached dependecy properties to set the Latitude and Longitude of the VEPushPin in order to be able to bind objects which are not DependencyObject. Therefore, I rely on style to map the data bound object properties to the VEPushPin container.
    <Style x:Key="{x:Type ve:VEPushPin}" TargetType="{x:Type ve:VEPushPin}" BasedOn="{StaticResource {x:Type ve:VEPushPin}}">
        <Setter Property="Latitude" Value="{Binding Path=Latitude, Mode=TwoWay}" />
        <Setter Property="Longitude" Value="{Binding Path=Longitude, Mode=TwoWay}" />
    </Style>
This solution lets the user full control on what to use to provide positionning information wihtout constaining him to implement a dedicated interface of event support Dependencey Property mechanism.

You'll find a zipped solution with the modified version of InfoStrat.VE and a sample application.
Feedback is welcome.

wrote Mar 22, 2009 at 2:54 PM

JoshB wrote Apr 17, 2009 at 6:35 PM

Aguerot,

Thanks for the information. I will take a look.

(Sorry I didn't see your comments, I didn't get notification on comments here, only in discussion.)

wrote Apr 23, 2009 at 7:18 PM

wrote Jan 30, 2010 at 9:36 PM

wrote Feb 14, 2013 at 3:02 AM

wrote May 16, 2013 at 8:27 AM

wrote May 16, 2013 at 8:27 AM

wrote Jun 14, 2013 at 7:08 AM