ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / LayoutView Class / ActivateMapFrame Method
The map frame to activate
Example

In This Topic
    ActivateMapFrame Method
    In This Topic
    Activate the map frame on the layout view. This method must be called on the UI thread.
    Syntax
    public void ActivateMapFrame( 
       MapFrame mapFrame
    )
    Public Sub ActivateMapFrame( _
       ByVal mapFrame As MapFrame _
    ) 

    Parameters

    mapFrame
    The map frame to activate
    Exceptions
    ExceptionDescription
    Map frame cannot be activated
    Needs to run on the GUI thread
    Layout view must be the active view
    Remarks
    Only one map frame can be activated on a given layout view instance at any given time. If a map frame is already activated on a specific view then it must be deactivated before attempting to activate another (map frame on it). When an input map frame is activated it will be selected if it was not already (selected). If CanActivateMapFrame returns false for the input map frame then a System.ArgumentException will be thrown. This method must be called on the UI thread (and not the MCT as is most commonly the case with most other synchronous API methods) or an System.InvalidOperationException will be thrown. The layout view you are activating the map frame "on" must be the current active view or an System.InvalidOperationException will be thrown.
    Example
    Activate Map Frame
    //The active view must be a layout view.
    var lv = LayoutView.Active;
    if (lv == null)
      return;
    var layout = lv.Layout;
    if (layout == null)
      return;
    
    //We can activate a map frame on the layout of the active view
    var map_frame = layout.GetElementsAsFlattenedList()
                       .OfType<MapFrame>().FirstOrDefault(mf => mf.Name == "Map 1");
    if (map_frame == null)
      return;
    //can we activate the map frame?
    if (lv.CanActivateMapFrame(map_frame))
      //activate it - Note: we are on the UI thread!
      lv.ActivateMapFrame(map_frame);
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.1 or higher.
    See Also