I am having an issue getting a selection to show up properly on a map while having the Editor commands refresh correctly. I have created a ViewModel that has a Property exposing a LayerCollection. Public Class LayerViewModel
Private _layerCollection As New ESRI.ArcGIS.Client.LayerCollection
Private WithEvents _selectionLayer As ESRI.ArcGIS.Client.FeatureLayer
Sub New()
CreateLayerCollection()
End Sub
Public ReadOnly Property ViewableLayers As ESRI.ArcGIS.Client.LayerCollection
Get
Return _layerCollection
End Get
End Property
Public Sub ClearSelectionLayer()
For Each feature In _selectionLayer.SelectedGraphics.ToList
feature.UnSelect()
Next
End Sub
Private Function CreateLayerCollection()
_layerCollection.Add(New ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer With {
.ID = "Parcels",
.Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"})
_selectionLayer = New ESRI.ArcGIS.Client.FeatureLayer With {
.ID = "Selection",
.Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0",
.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.SelectionOnly}
_layerCollection.Add(_selectionLayer)
Return (_layerCollection)
End Function
End Class
I bind the Map controlâ??s Layers Dependency Property to this my ViewModel property. <esri:Map x:Name="MyMap" Layers="{Binding ViewableLayers}" Extent="-117.19034671783447,34.051488876211806,-117.16030597686768,34.07294654833095" >
</esri:Map>
When I run the app and do a select no selected features are visible however the Remove and Clear buttons become enabled. When I uncomment the highlighted line of code below in my Views Code behind the selection shows up now but the Remove and Clear buttons do not enable. Can one explain why I am getting this behavior? I have modified the sample code from the Feature Layer Selection to include my new ViewModel approach http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerSelection Class MainWindow
Public WithEvents MyEditor As New ESRI.ArcGIS.Client.Editor
Private vm As New LayerViewModel
Sub New()
Resources.Add("MyEditor", MyEditor)
Me.DataContext = vm
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
EditorToolStrip.DataContext = MyEditor
MyEditor.Map = MyMap
End Sub
Private Sub MyEditor_EditCompleted(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Client.Editor.EditEventArgs) Handles MyEditor.EditCompleted
vm.ClearSelectionLayer()
End Sub
End Class