Rowland Shaw
Rowland Shaw

Reputation: 38130

Binding to a Map in a universal app

I'm working on a universal app, and for the Windows Store version, this wraps the Bing Maps control, based on code from Ricky Brunditt's blog

For testing purposes, I've tried to add a pushpin via XAML, with:

<Maps:MapControl ZoomLevel="14" MapServiceToken="{StaticResource MapServiceToken}" Width="630" Height="310" Center="{Binding Converter={StaticResource GeopointConverter}, Mode=OneWay}">
    <Maps:MapControl.Children>
        <BingMaps:Pushpin>
             <BingMaps:MapLayer.Position>
                 <BingMaps:Location Latitude="{Binding Latitude, Mode=OneWay}" Longitude="{Binding Longitude, Mode=OneWay}" />
             </BingMaps:MapLayer.Position>
        </BingMaps:Pushpin>
    </Maps:MapControl.Children>
</Maps:MapControl>

This does add the pin at the correct location, but if I pan the map, the pin doesn't pan with it. I'm probably just missing something silly, but why doesn't the pin pan with the map?

Upvotes: 1

Views: 1024

Answers (1)

Rowland Shaw
Rowland Shaw

Reputation: 38130

Ricky's sample inherits from a grid, and inserts the map control into it - this means any children are the children of the Grid, not the MapControl.

One option is to expose the encapsulated control's Children property with something like:

public MapUIElementCollection MapChildren
{
    get
    {
        return _map.Children;
    }
}

Upvotes: 1

Related Questions