5
votes

I'm developing a Windows Phone app that uses the older WP7 Microsoft.Phone.Controls.Maps.Map / Bing Map control.

The map tiles are being served up from a local source so the app doesn't not need a network connection to work. Unfortunately the map control insists on showing an "Unable to contact Server. Please try again later." message over the map when offline.

Does anyone know of a method to remove / hide this message?

Just in case you're curious - I'm developing a WP8 app but using the depreciated WP7 Bing map control as the new WP8 map control provides no method for replacing the Bing base map.

3

3 Answers

5
votes

i think this may suits you better:

void YourPage_Loaded(object sender, RoutedEventArgs e)
        {         
            m_Map.ZoomLevel = 11;          
            m_Map.LayoutUpdated += m_Map_LayoutUpdated; 
        }

        void m_Map_LayoutUpdated(object sender, EventArgs e)
        {
            if (!isRemoved) 
            {
                RemoveOverlayTextBlock();
            }
        }

        void  RemoveOverlayTextBlock()
        {             
            var textBlock = m_Map.DescendantsAndSelf.OfType<TextBlock>()
                           .SingleOrDefault(d => d.Text.Contains("Invalid Credentials") ||
                                                 d.Text.Contains("Unable to contact Server"));
            if (textBlock != null)
            {
                var parentBorder = textBlock.Parent as Border;
                if (parentBorder != null)
                {
                    parentBorder.Visibility = Visibility.Collapsed;
                }
                isRemoved = true;   
            }
       }

You have to include a class LinqToVisualTree witch can be downloaded from here. And here is the original post

0
votes

You can either handle the LoadingError event per instance or extend the Map control yourself as described in this post. You can then remove the layer than contains the error message so that it's not shown to the user.

public partial class CachedMap : Map
{
    public CachedMap() : base()
    {
        base.LoadingError += (s, e) =>
        {
            base.RootLayer.Children.RemoveAt(5);
        };
    }
}
0
votes

I know it's a very old thread, but anyways...

You can listen for LoadingError event as suggested @keyboardP, search for LoadingErrorMessage control in visual tree and simply hide it.

Map.LoadingError += MapOnLoadingError;

private void MapOnLoadingError(object sender, LoadingErrorEventArgs e)
{
    var errorMessage = Map.FindChildOfType<LoadingErrorMessage>();
    errorMessage.Visibility = Visibility.Collapsed;
}