ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / LayoutView Class / ZoomToSelectedElements Method
The amount of time to navigate the view to the new camera position. If null it uses the default navigation duration.
Example

In This Topic
    ZoomToSelectedElements Method (LayoutView)
    In This Topic
    Zoom the layout view to the extent of the selected elements. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public bool ZoomToSelectedElements( 
       Nullable<TimeSpan> duration
    )
    Public Function ZoomToSelectedElements( _
       Optional ByVal duration As Nullable(Of TimeSpan) _
    ) As Boolean

    Parameters

    duration
    The amount of time to navigate the view to the new camera position. If null it uses the default navigation duration.

    Return Value

    Returns true if the navigation is completed, false if it was interrupted by another view navigation.
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Example
    LayoutView_ZoomTo_SelectedElements
    //Set the layout view extent to the selected elements.
    
    //Process on worker thread
    await QueuedTask.Run(() =>
    {
      layoutView.ZoomToSelectedElements();
    });
    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