UI button bound to Editor.Add property never enables

741
3
04-12-2012 02:05 PM
markcheyne
Occasional Contributor
The setup

I have a map with two Snapshot operational feature layers - one contains points, the other polygons. One or the other can be edited at a time, though its counterpart displays related features.

My MainPage.xaml has a toolbar (StackPanel) with New and Edit buttons. The toolbar StackPanel DataContext is set to an Editor instance defined as a static resource on the page. The Editor in turn has its Map property bound to the page's map object.

The New button's Command is set to to {Binding Add} (The Editor's Add property), and its Edit button's Command is set to {Binding EditVertices} (The Edtor's EditVertices property)

My app sets the Where property on both layers to a particular ID so that only the 'current' feature in each is displayed. After I set the Where properties, I call Update() on each layer to send the request and get the current features. In the UpdateCompleted event handler, I set the Editor.LayerIDs property to the ID of the layer to edit.

The problem

At this point, I expect the New and Edit buttons to be enabled. If my edit layer is the polygon layer, they are. However, if the edit layer is the point layer, only the Edit button is enabled - the New button is always disabled. I read the API Reference for the Editor.Add property, it states that Add will be enabled only if LayerIDs references a single layer (it is as described above), and if the FeatureLayer is read-only (it isn't), Add will not be supported.

So why is Add disabled, and why is it only disabled for one of my two layers?

Thank you, Mark
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
If you have more than one layer in your Editor (i.e. LayerIDs is not set and Map has more than 1 editable layer and/or LayerIDs is set but with more than 1 layer), Add button will be disabled.

You will need to separate the Add editors like so.
  <Grid.Resources>
   <esri:Editor x:Key="Layer1AddEditor" Map="{Binding ElementName=MyMap}"
       LayerIDs="MyFeatureLayerID1"
       GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>

   <esri:Editor x:Key="Layer2AddEditor" Map="{Binding ElementName=MyMap}"
       LayerIDs="MyGraphicsLayerID2"
       GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
  </Grid.Resources>


  <Button Content="Add" DataContext="{StaticResource Layer1AddEditor}"
    Command="{Binding AddParameter}" CommandParameter="MyFeatureTypeID"/>
  <Button Content="Add" DataContext="{StaticResource Layer2AddEditor}"
    Command="{Binding AddParameter}" CommandParameter="{StaticResource MySymbol}"/>
0 Kudos
markcheyne
Occasional Contributor
thanks Jennifer for always being there!

however, this time that wasn't it. It turns out that for my point layer, I *must* provide a CommandParameter for binding my 'New' button to the Editor.Add property. Like this:

<Button x:Name="EditNew" Content="New" Margin="0,0,0,0" Command="{Binding Add}" CommandParameter="U" />

When editing my polygon layer, the CommandParameter can remain an empty string.

This really caught me by surprise - it's not like my point layer has subtypes. However, and I think this is the crux - it has an attribute SITE_TYPE that we are using for symbolization in the map service's MXD. It is one of those values that I must provide as the CommandParameter in order for the button bound to the Editor.Add property to enable.

So that solves my 'the New button won't enable' problem. Thanks!

However, even though I am specifying a CommandParameter value that somehow the API knows should be a SITE_TYPE value, it doesn't appear to *do* anything with the value - it doesn't automatically set the SITE_TYPE for the new point, for example. Hmmm... No biggie, I'll figure that out...
0 Kudos
JenniferNery
Esri Regular Contributor
Editor.Add command will set graphic.Attributes based on type ID so your layer renderer can get a symbol for this graphic.

So is Add button working for you now? Are you getting the correct symbol? Can you check that its attributes are properly set?

Basically if you look at this service, http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer.... Under "Types" section, there is a "Prototype" section where Attributes are pre-defined. These are the values Editor.Add will try to add to your graphic.Attributes. They are also the same attributes, your renderer use (see "Drawing Info").
0 Kudos