/// <summary>
        /// Creates a new mapviewpane (and a map as well if need-be) or closes the mapviewpane if it already exists
        /// </summary>
        /// <param name="selectedMapview"></param>
        private async void CreateAndViewMapPane(MapviewItem selectedMapview)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine("CreateAndViewMapPane start");
                var newMapName = selectedMapview.MapviewName;
                {
                    var mapPanes = ProApp.Panes.OfType <IMapPane>();
                    foreach (Pane pane in mapPanes)
                    {
                        if (pane.Caption == newMapName)
                        {
                            ProApp.Panes.ClosePane(pane.InstanceID);
                            UpdateHasMapView(selectedMapview.MapName, false);
                            return;
                        }
                    }
                }
                var newExtent = selectedMapview.Extent;
                // we need to find or create a map with a given selectedMapview.MapviewName
                // 1: does the map already exist?
                MapProjectItem mapProjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item =>
                                                                                                        item.Name.Equals(newMapName));
                if (mapProjItem != null)
                {
                    // we found the existing MapProjectItem
                    var mapPanes = ProApp.Panes.OfType <IMapPane>();
                    foreach (Pane pane in mapPanes)
                    {
                        if (pane.Caption == newMapName)
                        {
                            ProApp.Panes.ClosePane(pane.InstanceID);
                            UpdateHasMapView(selectedMapview.MapName, false);
                            return;
                        }
                    }
                    //Opening the map in a mapview
                    await QueuedTask.Run(async() =>
                    {
                        await ProApp.Panes.CreateMapPaneAsync(mapProjItem.GetMap());
                    });

                    UpdateHasMapView(selectedMapview.MapName, true);
                }
                else
                {
                    await CreateMapThruCopy(newMapName, newExtent);

                    UpdateHasMapView(selectedMapview.MapName, true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($@"An error occurred in CreateAndViewMapPane: {ex.ToString()}");
            }
            finally
            {
                System.Diagnostics.Debug.WriteLine("CreateAndViewMapPane end");
            }
        }
 /// <summary>
 /// Checks or Unchecks the "HasViewPane" checkbox.  Then clears the current selection
 /// </summary>
 /// <param name="MapName"></param>
 /// <param name="newHasMapView"></param>
 private void UpdateHasMapView(string MapName, bool newHasMapView)
 {
     Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() =>
     {
         lock (_lockCollection)
         {
             if (SelectedMapview != null)
             {
                 System.Diagnostics.Debug.WriteLine("UpdateHasMapView start");
                 SelectedMapview.HasViewPane = newHasMapView;
                 // clear the selection
                 SelectedMapview = null;
                 System.Diagnostics.Debug.WriteLine("UpdateHasMapView end");
             }
         }
     }));
 }