/// <summary> /// Use this to optinally add the layers to this Person Form. /// </summary> /// <param name="layers"></param> public void AddLayers(List <Layer> layers) { LayerComboBox.BeginUpdate(); foreach (Layer layer in layers) { LayerComboBox.Items.Add(LayerComboBox.Items.Count + ": " + layer.Name); } LayerComboBox.EndUpdate(); }
/// <summary> /// This refresh method is called when the active map view changes and therefore the list of layers needs to be refreshed /// </summary> public void RefreshLayerComboBox() { try { if (LayerComboBox == null) { _deferredRefreshOfLayerList = true; return; } LayerComboBox.ClearItems(); QueuedTask.Run(() => { Map map = MapView.Active.Map; if (map == null) { return; } var layers = map.GetLayersAsFlattenedList().OfType <FeatureLayer>(); bool hasItems = false; foreach (var lyr in layers) { string fc = lyr.Name; LayerComboBox.AddItem(new ComboBoxItem(fc)); hasItems = true; } if (hasItems) { LayerComboBox.Text = "Choose..."; // LayerComboBox.Text = LayerComboBox.ItemCollection.FirstOrDefault().ToString(); } }); } catch (Exception ex) { MessageBox.Show("Error in RefreshLayerComboBox: " + ex.ToString(), "Error"); } }