ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / LayoutView Class / Layout Property
Example

In This Topic
    Layout Property (LayoutView)
    In This Topic
    Gets the layout associated with the layout view.
    Syntax
    public Layout Layout {get;}
    Public ReadOnly Property Layout As Layout
    Example
    LayoutView_SetSelection
    //Set the layout's element selection.
    
    await QueuedTask.Run(() =>
    {
      Element rec = layoutView.Layout.FindElement("Rectangle");
      Element rec2 = layoutView.Layout.FindElement("Rectangle 2");
    
      List<Element> elmList = new List<Element>();
      elmList.Add(rec);
      elmList.Add(rec2);
    
      layoutView.SelectElements(elmList);
    });
    LayoutView_LayoutFrameWorkExtender
    //This sample checks to see if a layout project item already has an open application pane.  
    //If it does, it checks if it is the active layout view, if not, it creates, activates and opens a new pane.
    
    //Reference a layoutitem in a project by name
    LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout View"));
    
    //Get the layout associated with the layoutitem
    Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout());
          
    //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it
    foreach (var pane in ProApp.Panes)
    {
      var layoutPane = pane as ILayoutPane;
      if (layoutPane == null)  //if not a layout pane, continue to the next pane
        continue;
      if (layoutPane.LayoutView.Layout == lyt)  //if the layout pane does match the layout, activate it.
      {
        (layoutPane as Pane).Activate();
        layoutPane.Caption = "This is a test";
        System.Windows.MessageBox.Show(layoutPane.Caption);
        return;
      }
    }
    //Otherwise, create, open, and activate the layout if not already open
    ILayoutPane newPane = await ProApp.Panes.CreateLayoutPaneAsync(lyt);
    
    //Zoom to the full extent of the layout
    await QueuedTask.Run(() => newPane.LayoutView.ZoomTo100Percent());
    LayoutViewClassExample1
    //This example references the active layout view.  Next it finds a couple of elements and adds them to a collection. 
    //The elements in the collection are selected within the layout view.  Finally, the layout view is zoomed to the
    //extent of the selection.
    
    // Make sure the active pane is a layout view and then reference it
    if (LayoutView.Active != null)
    {
      LayoutView lytView = LayoutView.Active;
      //Reference the layout associated with the layout view
      Layout lyt = await QueuedTask.Run(() => lytView.Layout);
    
      //Find a couple of layout elements and add them to a collection
      Element map1 = lyt.FindElement("Map1 Map Frame");
      Element map2 = lyt.FindElement("Map2 Map Frame");
      List<Element> elmList = new List<Element>();
      elmList.Add(map1);
      elmList.Add(map2);
    
      //Set the selection on the layout view and zoom to the selected elements
      await QueuedTask.Run(() => lytView.SelectElements(elmList));
      await QueuedTask.Run(() => lytView.ZoomToSelectedElements());
    }
    LayoutViewClassExample2
    // Make sure the active pane is a layout view and then reference it
    if (LayoutView.Active != null)
    {
      LayoutView lytView = LayoutView.Active;
      //Reference the layout associated with the layout view
      Layout lyt = await QueuedTask.Run(() => lytView.Layout);
    
      //Find a couple of layout elements and add them to a collection
      Element map1 = lyt.FindElement("Map1 Map Frame");
      Element map2 = lyt.FindElement("Map2 Map Frame");
      List<Element> elmList = new List<Element>();
      elmList.Add(map1);
      elmList.Add(map2);
    
      //Set the selection on the layout view and zoom to the selected elements
      await QueuedTask.Run(() => lytView.SelectElements(elmList));
      await QueuedTask.Run(() => lytView.ZoomToSelectedElements());
      return true;
    }
    return false;
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also