ArcGIS Pro SDK 切换所有图例项的自动可见性

发布时间 2023-04-14 21:32:50作者: gisai
 protected void setLegend()
        {
            var lyt = LayoutView.Active?.Layout;
            if (lyt == null)
                return;
            QueuedTask.Run(() =>
            {
                var def = lyt.GetDefinition();
                var legend = def.Elements.OfType<CIMLegend>().FirstOrDefault();
                if (legend != null)
                {
                    //toggle auto visibility of all the legend items
                    foreach (var leg_item in legend.Items)
                    {
                        leg_item.AutoVisibility = !leg_item.AutoVisibility;
                    }
                    //commit the change
                    lyt.SetDefinition(def);
                }
            });
        }