1

Same issue as Adding MapControl in xaml results in a "Catastropic failure" , the bing map control cannot be collapsed without causing a catastrophic exception. Worse, just put a map inside a collapsed container and it will crash too. It means that every parent, grandparent, and so on MUST be collapsed using code behind. breaking mvvm pattern for no reason just to display and hide a map.

Is there someone who found a workaround ? It's crazy that MS didn't fix their own control for such a long time even when they know it doesn't behave as intended.. Any help is appreciated !

Community
  • 1
  • 1
MakanWG
  • 175
  • 11

1 Answers1

1

This is the first time I've heard of this issue. It's worth noting that the map control in WP8.1 wasn't created by Microsoft, but Nokia. In Windows 10 Microsoft took the Nokia control and combined with the features of the Windows 8 map control and made it much more stable.

Update: I've taken a look at this issue. It's not easy to figure out what is causing the error as the map control is written in native C++ and the error that is thrown has inaccessible properties that show up as "?". That said, I did manage to figure out a workaround. Collapsing a control is not much different than giving a control a width and height of 0. With this in mind here is a code sample of how to show/hide the map using width/height instead of visibility.

<Page
    x:Class="WP81App.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WP81App"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
     xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps" 
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Maps:MapControl Name="MyMap" Height="0" Width="0" />
        <Button Content="Show Map" Click="ShowMapBtn_Clicked" HorizontalAlignment="Center"/>
    </Grid>
</Page>

Button handler:

private void ShowMapBtn_Clicked(object sender, RoutedEventArgs e)
{
    var mapContainer = MyMap.Parent as FrameworkElement;
    MyMap.Width = mapContainer.ActualWidth;
    MyMap.Height = mapContainer.ActualHeight;

    //Hide the button
    (sender as Button).Visibility = Visibility.Collapsed;
}
rbrundritt
  • 16,570
  • 2
  • 21
  • 46
  • Aw, seems like I attracted the Bing map's big guy ! Maybe you're part of the few people that can find a workaround. Do you have a way to watch/ do something about this weird behavior ? Just creating a new Phone 8.1 project (not Silverlight) and adding a collapsed map to the main page should trigger the exception. – MakanWG Nov 25 '15 at 09:17
  • I've come up with a workaround and updated my answer with it. – rbrundritt Nov 25 '15 at 19:48
  • This will work in the very specific case where you want to hide the map itself from it's container. But let's say that the map is part of a UserControl which is also part of another UserControl. It becomes impossible to collapse one of those via binding (and converter) because it will trigger the exception. By the way, collapsing the map directly by code behind will always work. Collapsing it by xaml or collapsing any of it's ancestor container will always trigger the exception. – MakanWG Nov 26 '15 at 17:16
  • This is a workaround that will work in most scenarios. This is a known issue that is unlikely to be fixed as this map control was replaced in Windows 10. – rbrundritt Nov 30 '15 at 17:49