ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapView Class / GetSelectedLayers Method
Example Version

GetSelectedLayers Method
Returns the collection of layers selected in the TOC.
Syntax
public IReadOnlyList<Layer> GetSelectedLayers()

Return Value

The collection of layers selected in the TOC.
Example
Zoom To Selected Layers
public Task<bool> ZoomToTOCSelectedLayersAsync()
{
  //Get the active map view.
  var mapView = MapView.Active;
  if (mapView == null)
    return Task.FromResult(false);

  //Zoom to the selected layers in the TOC
  var selectedLayers = mapView.GetSelectedLayers();
  return mapView.ZoomToAsync(selectedLayers);
}
Pan To Selected Layers Asynchronous
public Task<bool> PanToTOCSelectedLayersAsync()
{
  //Get the active map view.
  var mapView = MapView.Active;
  if (mapView == null)
    return Task.FromResult(false);

  //Pan to the selected layers in the TOC
  var selectedLayers = mapView.GetSelectedLayers();
  return mapView.PanToAsync(selectedLayers);
}
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also