Windows phone map control doesn’t render in ContentControl

While working on a mapping framework agnostic of GIS implementation, I attempted creating a MapView that will host a vendor specific map object as follows:


<!--LayoutRoot is the root grid where all page content is placed-->
 <Grid x:Name="LayoutRoot" Background="Transparent">
 <Grid.RowDefinitions>
 <RowDefinition Height="Auto"/>
 <RowDefinition Height="*"/>
 </Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
 <StackPanel Grid.Row="0" Margin="12,17,0,28">
 <TextBlock Text="agnostic mapper" Style="{StaticResource PhoneTextNormalStyle}"/>
 <TextBlock Text="map" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
 </StackPanel>

<!--ContentPanel - place additional content here-->
 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

<Grid.RowDefinitions>
 <RowDefinition Height="*"/>
 <RowDefinition Height="Auto"/>
 </Grid.RowDefinitions>

<ContentControl Name="MapContentControl" Content="{Binding MainMapView, Mode=OneTime}"/>

 </Grid>
 </Grid>

The view will be bound to an instance of MapViewModel implemented as follows:


 public class MapMainViewModel : ViewModelBase, IMapViewModel
 {
  public IMapViewController MapViewController { get; protected set; }

 public MapMainViewModel(IMapViewController mapViewController)
 {
 MapViewController = mapViewController;
 }

 public object MainMapView
 {
   get
   {
    return MapViewController.GetMapObject();
   }
 }

 public IMvxCommand ShowLegendCommand
 {
  get { return new MvxCommand(() => ShowViewModel<LegendViewModel>()); }
 }

 public void DrawPendingLayers()
 {
   MapViewController.DrawPendngLayers();
 }

 protected override void Dispose(bool disposing)
 {
   if (disposing)
   {
     MapViewController.DisposeActiveMapContext();
   }
  }
 }

For some reason, yet to be determined, if the the ViewModel returns an instance of Microsoft Windows Phone Map control, we do not see anything.  We expect to see a base map of the world, like so:

windows-phone-map-does-not-display-in-contentcontrol

However, if we return an instance of ThinkGeo MapSuite Map or even ESRI ArcGIS Map controls for Windows Phone, we do see a map.

If you run into this, change the hosting container from a ContentControl to a Border control as follows:

<Border Name="MapContentControl" Child="{Binding MainMapView, Mode=OneTime}"></Border>

With this minor change, any of the three maps should be rendered correctly.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s