ArcGIS Pro 2.8 API Reference Guide
SetCamera(Layer,Boolean) Method
Example 

ArcGIS.Desktop.Layouts Namespace > MapFrame Class > SetCamera Method : SetCamera(Layer,Boolean) Method
Layer
Sets the map frame extent using the a layer's extent. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public void SetCamera( 
   Layer layer,
   bool useSelectedFeatures
)
Public Overloads Sub SetCamera( _
   ByVal layer As Layer, _
   Optional ByVal useSelectedFeatures As Boolean _
) 

Parameters

layer
Layer
useSelectedFeatures
Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Remarks
SetCamera will have no effect a map frame's extent being driven by a map series.
Example
//Zoom map frame to the extent of a single layer.

//Perform on the worker thread
await QueuedTask.Run(() =>
{
  //Reference MapFrame
  MapFrame mf = layout.FindElement("Map Frame") as MapFrame;

  //Reference map and layer
  Map m = mf.Map;
  FeatureLayer lyr = m.FindLayers("GreatLakes").First() as FeatureLayer;

  //Set the map frame extent to all features in the layer
  mf.SetCamera(lyr, false);
});
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

MapFrame Class
MapFrame Members
Overload List