Better way to specify "parent" map than using MapName

Developer
Jun 17, 2010 at 4:47 AM

I initially suggested adding the MapName property so that the toolkit controls could easily be added to a map by associating the two together using the "parent" maps name. Implemented this way, it works similar to the way ASP.NET developers are familiar with Extender controls.

However, there is a better way to do this in Silverlight. Just add a ParentMap property (as a DependencyProperty), then when the property is changed just add the appropriate hooks to connect the two together.

Here's the example from the ExampleSite on using the MiniMap control:

<UserControl x:Class="ExampleControlBing.ControlDemos.MiniMapExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
xmlns:mm="clr-namespace:DeepEarth.BingMapsToolkit.Client.Controls;assembly=DeepEarth.BingMapsToolkit.Client.Controls.MiniMap">
<Grid x:Name="LayoutRoot">
<m:Map x:Name="map" CredentialsProvider="AiVLrtsVAvAA3EffDzr9vSwQI2QPULj8xCFpI1k6DBBgtH33OCEhmNmzcV4MjNSa" Center="-27,153" ZoomLevel="16" />
<mm:MiniMap Name="minimap" MapName="map" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="4,4,4,4"/>
</Grid>
</UserControl>

Now, here's what the usage would look like with the suggested "ParentMap" property:

<UserControl x:Class="ExampleControlBing.ControlDemos.MiniMapExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
xmlns:mm="clr-namespace:DeepEarth.BingMapsToolkit.Client.Controls;assembly=DeepEarth.BingMapsToolkit.Client.Controls.MiniMap">
<Grid x:Name="LayoutRoot">
<m:Map x:Name="map" CredentialsProvider="AiVLrtsVAvAA3EffDzr9vSwQI2QPULj8xCFpI1k6DBBgtH33OCEhmNmzcV4MjNSa" Center="-27,153" ZoomLevel="16" />
<mm:MiniMap Name="minimap" ParentMap="{Binding ElementName=map}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="4,4,4,4"/>
</Grid>
</UserControl>

The capability of "Element to Element" binding that the "{Binding ElementName=map}" is taking advantage of was added in Silverlight 3. So, if you still need to support SL2 this solution wont work, but if your targeting SL3+ then this is a better way of doing it.

Coordinator
Jun 17, 2010 at 11:12 PM

That is much better Chris, we in the process of a brand new SL4 version so we will change to this for sure. We're also trying to make a common interface in the new version so all toolkit controls work with both the DE and Bing Maps control. The simple idea being that the DE control can impliment all the properties, methods and events with its standard set of types, we can inherit from the Bing Maps control and impliment the new interface providing a one off mapping between the Bing Maps class to the DE classes. Then developers can make one awesome control and have it work on both a pure open source control and the commerically support Microsoft control. What do you think? In this new case the dependancy property used here would just be the interface, I assume that will work ok.

Developer
Jun 18, 2010 at 1:19 AM
That sounds like it would work. Also, you could have the Dependency Property be of type Object. Then when the "ParentMap" property is set you could just determine if its a DeepEarth or Bing Maps map control and do things appropriately for the specific map control in use.