A project can contain multiple layouts. A layout view is a pane that displays the view of a layout. Layout views are the primary interface used to display, navigate, and select layout elements. The layout being visualized in the view can be accessed via the Layout property.
There can be multiple layout views open at a given time, but there can only be one active layout view. The active layout view will set the context for the ribbon and many of the dock panes in the application. The Active property will return null if there is no active layout view.
The layout view has several "ZoomTo" nagivation methods and it also provides the context for managing selected items in the Contents pane. For example, the GetSelectedElements method returns a collection of selected page layout elements.
//Reference the active layout view. //Confirm if the current, active view is a layout view. //If it is, do something. LayoutView activeLayoutView = LayoutView.Active; if (activeLayoutView != null) { // do something }
//Get element's selection count. //Count the number of selected elements on the active layout view LayoutView activeLayoutView = LayoutView.Active; if (activeLayoutView != null) { var selectedElements = activeLayoutView.GetSelectedElements(); ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($@"Selected elements: {selectedElements.Count}"); }
//Set the active layout view's selection to include 2 rectangle elements. //Reference the active view LayoutView activeLayoutView = LayoutView.Active; if (activeLayoutView != null) { //Perform on the worker thread QueuedTask.Run(() => { //Reference the layout Layout lyt = activeLayoutView.Layout; //Reference the two rectangle elements Element rec = lyt.FindElement("Rectangle"); Element rec2 = lyt.FindElement("Rectangle 2"); //Construct a list and add the elements List<Element> elmList = new List<Element> { rec, rec2 }; //Set the selection activeLayoutView.SelectElements(elmList); }); }
System.Object
ArcGIS.Desktop.Layouts.LayoutView
Target Platforms: Windows 11, Windows 10