AnsweredAssumed Answered

Access to LegendItems

Question asked by mstranovsky on Nov 1, 2017

private async Task editLegend()
{

   await QueuedTask.Run(() =>

   {

     LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(wksName + "_Layout"));
      if (layoutItem != null)
      {
         Layout layout = layoutItem.GetLayout();
         if (layout != null)
         {
            ArcGIS.Desktop.Layouts.Legend legendElm = layout.FindElement("Legend") as ArcGIS.Desktop.Layouts.Legend;
            if (legendElm != null)
            {
                  CIMLegend cimLeg = legendElm.GetDefinition() as CIMLegend;
                  foreach (CIMLegendItem legItem in cimLeg.Items)
                  {   

                     legItem.ClassIndent = 0;

                     legItem.HeadingIndent = 0;
                     legItem.LayerNameIndent = 0;
                     legItem.ShowGroupLayerName = false;
                     legItem.ShowLayerName = false;
                     legItem.ShowHeading = false;
                     legItem.ShowDescription = false;
                     legItem.ShowLabels = true;
                  }

            }
         }
      }
   });
   await Project.Current.SaveAsync()

}

 

This does not work.  It is not unchecking the "Show" values in the legend item properties, nor is it not changing the indent values as well.   

Outcomes