How do I add a background color to an ArcGIS Pro map frame using C# in ArcGIS Pro SDK?

2279
5
08-14-2018 01:10 PM
Highlighted
New Contributor II

Hello,

I can not seem to figure out how to add a background color to an ArcGIS Pro map frame using C# in ArcGIS Pro SDK. For example, I can programmatically add a new map frame to a layout, but I would then like to set a blue background color for the map frame. I cannot seem to find any documentation on this. Any help would be much appreciated.

Thank you!

Tags (1)
0 Kudos
5 Replies
Highlighted
Regular Contributor

If the API doesn't expose a method or property for your needs you can usually try the underlying 'Cartographic Information Model' (CIM) for that class.  So specifically for the Map class you can find a BackgroundColor property in the corresponding CIMMap class.  This code snippet will work for you:

if (MapView.Active?.Map == null) return;
QueuedTask.Run(() =>
   {
       var cimMap = MapView.Active.Map.GetDefinition();
       cimMap.BackgroundColor = CIMColor.CreateRGBColor(0, 0, 255, 138);
       MapView.Active.Map.SetDefinition(cimMap);
   });

Hope this helps.

0 Kudos
Highlighted
New Contributor II

Thank you. The solution above, added a blue background to the active map within my map frame, but did not add a blue background to the map frame (within the layout view) itself. I am trying to change the background symbol (located in the format map frame pane) to blue (see image).

Thank you!

0 Kudos
Highlighted
New Contributor II

I'm wondering if anyone has any knowledge on using ArcGIS Pro SDK to add a background color to the map frame itself. Here is a graphic that displays the background feature that I am trying to change to blue.

Thank you!

0 Kudos
Highlighted
Esri Regular Contributor

Hi Joshua

Here is a code snippet that can change the map frame's background.  

Thanks!

Uma

protected override void OnClick()
        {
            QueuedTask.Run(() =>
            {
                //Get the layout
                var layout = Project.Current.GetItems<LayoutProjectItem>()?.First().GetLayout();
                if (layout == null) return;
                //Get the map frame in the layout
                MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame;
                if (mapFrame == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
                    return;
                }
                //Get the map frame's definition in order to modify the background.
                var mapFrameDefn = mapFrame.GetDefinition() as CIMMapFrame;
                //Construct the polygon symbol to use to create a background
                var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlueRGB, SimpleFillStyle.Solid);
                //Set the background
                mapFrameDefn.GraphicFrame.BackgroundSymbol = polySymbol.MakeSymbolReference();
                //Set the map frame defintion
                mapFrame.SetDefinition(mapFrameDefn);

            });
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Highlighted
New Contributor II

Perfect, this worked great.

Much appreciated.

Thanks!

0 Kudos