Adding MapControl in xaml results in a "Catastropic failure"
Asked Answered
A

2

11

I am creating an universal application using Visual Studio Ultimate 2013 Version 12.0.30501.00 Update 2. I am getting Catastrophic failure on adding Map Control in my xaml like this

<Maps:MapControl Visibility="Collapsed"/>. 

I have added

xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps" 

in the page header and added 'location' capability to application manifest file. Has anyone faced the same issue? You can test his by creating a sample application and add only MapControl. Please help me to resolve this issue.

The problem is observed in normal Windows Phone 8.1 applications also. Am i missing something here?

The problem is observed when i try to run the application in emulator.

The error does not show any other information just 'catastropic failure', nothing else.

May be i will try to re-install Visual Studio. But one more interesting fact is that i could get it working if i am not hiding the map control in the page.

Can you test it by creating a sample application and just making the map control Visibility='Collapsed'?

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

    <Grid>
        <Maps:MapControl Visibility="Collapsed" />
    </Grid>
</Page>

And the problem is observed in more than one PC.

Acro answered 13/6, 2014 at 22:37 Comment(1)
I have exactly the same problem so this is not fixed yetHyder
G
6

I've tested your example and indeed there is such a problem also on my Phone.

As I have checked it is possible to set Collapsed from code - so as a workaround:

<Grid>
   <Maps:MapControl Name="myMap" Visibility="Visible" />
</Grid>

In the code behind:

public MainPage()
{
    this.InitializeComponent();
    this.Loaded += (sender, e) => myMap.Visibility = Visibility.Collapsed;
}
Gelt answered 14/6, 2014 at 10:2 Comment(1)
Thanks. Hiding the control in the code is working as you have mentioned.Acro
Y
1

I've come up with a workaround for this. Instead of using visibility you can use the maps height/width properties to hide/show the map. Set them to 0 when you want to hide it, and set it to the parents width/height when you want to show it. Here is a code sample:

<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;
}
Yetac answered 25/11, 2015 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.