I tried the HowDoI sample\GettingStarted\HideOrShowAFeatureLayer by replacing the following code, it works fine. Could you try this in your environment? private void cbkShowLayer_CheckedChanged(object sender, RoutedEventArgs e) { //if (wpfMap1.Overlays.Count > 0) //{ // wpfMap1.FindFeatureLayer("WorldLayer").IsVisible = cbkShowLayer.IsChecked.Value; // wpfMap1.Refresh(wpfMap1.Overlays["WorldOverlay"]); //}
if (wpfMap1.Overlays.Count > 0) { FeatureLayer featureLayer = wpfMap1.FindFeatureLayer("WorldLayer"); featureLayer.Open();
//wpfMap1.CurrentExtent = featureLayer.GetBoundingBox(); wpfMap1.CurrentExtent = new RectangleShape(-94.0427372387695, 32.3991367749023, -93.8323619433594, 32.1154849597168);
From the stack trace, it seems that the problem root is the background of the MapControl, I am wondering if there is any special code in it?
If you still have problem, could you send us a small sample application to show us your problem? That would be very helpful to find out and fix the problem.
Hardcoding the values does prevent the exception from happening.
The problem seems related to how I set the CurrentExtent upon the initial load/display of the map. When I initially display my map, I haven't yet loaded any features into it, but for some reason if I do not set my extents to the feature set bounding box (unknown at this time), then I get the exception. By hardcoding the value in, the value was set upon initial load. Then, when the user selects the dataset they wish to view, I reset the extents to match this new, user selected data set.
So... for example. The code below doesn't work. (initialSetup is true only during the initial setup of wpfMap (i.e., true during construction)
I found a workaround for my problem. I created a BeginUpdate / EndUpdate concept which prevented other code from successfully refreshing until I decide. I determined that a refresh was coming in around the time the code to reset the extents was happening.