This is a migrated thread and some comments may be shown as answers.

Map component crashes when switching modes using Bing Provider

2 Answers 65 Views
Map
This is a migrated thread and some comments may be shown as answers.
Hafsa
Top achievements
Rank 1
Hafsa asked on 04 May 2015, 03:04 PM

Hi,

I have a custom WPF control that contains the RadMap in its control template. The provider is Bing and the mode is set to "Road" mode. When switching the map to Aerial mode, the application crashes and I see the following error:

InvalidOperationException was unhandled: Cannot set a property on object 'Telerik.Windows.Controls.Map.BingMapProvider' because it is in a read-only state.

 This does not happen with the ArcGIS or OSM provider. I would really like to use the Bing provider though... any idea what might be causing this?

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 07 May 2015, 11:53 AM
Hello Hafsa,

The reported behavior is caused by the fact that the BingMapProvider derives from the Freezable class. When you define a freezable object in a DataTemplate, ControlTemplate or any resource, the WPF framework automatically freezes it and it cannot be further modified. This is why when you define RadMap into the ControlTemplate of the custom control the exception is thrown when the provider's Mode property is changed.

The OpenStreeMap and ArcGIS providers are also freezable object, but their mechanism of changing the view mode is different and this exception doesn't occur. 

In order to resolve this for the BingMapProvider you can create a custom provider that derives from the bing map and override its FreezeCore() method, then cancel the freezing. Here is an example:
public class MyBingProvider : BingMapProvider
{
    protected override bool FreezeCore(bool isChecking)
    {
        return false;
    }
}

<telerik:RadMap>
    <telerik:RadMap.Provider>      
        <local:MyBingProvider />
    </telerik:RadMap.Provider>
</telerik:RadMap>
Please try this approach and let me know if it works for you.

Regards,
Martin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Hafsa
Top achievements
Rank 1
answered on 08 May 2015, 04:09 AM
This works great. Thank you!
Tags
Map
Asked by
Hafsa
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Hafsa
Top achievements
Rank 1
Share this question
or