1

Can I select a layer, by code, in the TOC/legend of a map in a WPF ArcGIS Runtime application?

I develope in ArcGIS Runtime SDK 10.2.2 for .Net in C#.

Kirk Kuykendall
25.9k9 gold badges68 silver badges155 bronze badges
asked Jun 2, 2015 at 6:13
1
  • The .NET ArcGIS Runtime does not use ArcObjects, it uses its own .NET SDK (that is built on top of ArcObjects). That being said, have a look at the Layers namespace in the API Documentation: developers.arcgis.com/net/desktop/api-reference Commented Jun 2, 2015 at 12:11

1 Answer 1

1

Solved.

There is a property named IsSelected in ESRI.ArcGIS.Client.Toolkit.Primitives.LegendItemViewModel class, so I had to find my layer by service and sublayerId and set this property to true.

 ESRI.ArcGIS.Client.Toolkit.Primitives.LegendItemViewModel layer = ControlObjMap.Control.Object.LegendExtension.BusquedaItemSublayerId(leyenda.LayerItems, layerService, layerIndex);
 if (layer != null)
 layer.IsSelected = true;
 public static ESRI.ArcGIS.Client.Toolkit.Primitives.LegendItemViewModel BusquedaItemSublayerId(
 this IEnumerable<ESRI.ArcGIS.Client.Toolkit.Primitives.LayerItemViewModel> layerItems,string serviceName, int sublayerId)
 {
 if (layerItems == null)
 return null;
 ESRI.ArcGIS.Client.Toolkit.Primitives.LegendItemViewModel layer = null;
 foreach (var layerItem in layerItems)
 {
 if (layerItem.LayerItems != null)
 {
 layer = layerItem.LayerItems.BusquedaItemSublayerId(serviceName, sublayerId);
 }
 else if ((layerItem.Layer is ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer || layerItem.Layer is ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer) && 
 layerItem.SubLayerID == sublayerId)
 {
 if ((layerItem.Layer is ESRI.ArcGIS.Client.DynamicMapServiceLayer && ((ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)layerItem.Layer).Url == serviceName)||
 (layerItem.Layer is ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer && ((ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer)layerItem.Layer).Url == serviceName)
 )
 layer = layerItem;
 }
 if (layer != null)
 return layer;
 }
 return null;
 }
answered Jun 3, 2015 at 5:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.