Select to view content in your preferred language

How to create a non-editable field in a FeatureDataForm

6264
5
02-10-2011 10:36 AM
DonFreeman
Emerging Contributor
Given a FeatureLayer defined like this:
     <esri:FeatureLayer ID="AMAvailableLayer" 
      Url="http://gismaps.pagnet.org/ArcGIS/rest/services/testprojectALLBikeCounts/FeatureServer/0"
      MouseLeftButtonUp="AllAvailableFeatureLayer_MouseLeftButtonUp"
      SelectionColor="Yellow"
      OutFields="Location,VolunteerAM,PhoneAM,EmailAM,SpanishAM"
      Where="VolunteerAM = 'Available' and VolunteerPM != 'Available'"    
      Renderer="{StaticResource AMRenderer}"
      DisableClientCaching="True" >
      <esri:FeatureLayer.MapTip>
       <Border CornerRadius="10" BorderBrush="SaddleBrown" BorderThickness="3" Margin="0,0,15,15" Background="LightGray">
        <StackPanel Margin="7">
         <StackPanel Orientation="Horizontal">
          <TextBlock Text="Location: " Foreground="Black" FontWeight="Bold"/>
          <TextBlock Text="{Binding [Location]}" Foreground="Black" />
         </StackPanel>
        </StackPanel>
       </Border>
      </esri:FeatureLayer.MapTip>
     </esri:FeatureLayer>
and a FeatureDataForm defined like this:
      <esri2:FeatureDataForm x:Name="MyFeatureDataForm"   
       FeatureLayer="{Binding Path=Layers[AllAvailableFeatureLayer], ElementName=MyMap}" 
       IsEnabled="True"
                            IsReadOnly="False" 
       LabelPosition="Left"
       CommitButtonContent="Save"
       EditEnded="MyFeatureDataForm_EditEnded" >
      </esri2:FeatureDataForm>
How can you make one of the fields ('Location') NOT editable?

Thanks
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
FeatureDataForm marks fields as read-only when the service have marked them read-only. See Fields section in this document: http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#//009300000021....

While you cannot change the field to read-only, you can hide this read-only field by not including it in your FeatureLayer OutFields.

This is a related thread:  http://forums.arcgis.com/threads/20521-How-to-set-some-attributes-readonly-for-FeatureDataForm
0 Kudos
DonFreeman
Emerging Contributor
Thanks Jenn -
I can't leave the fields out of the outfields because I do want to display their values both in a maptip and in the FeatureDataForm (or along side of it). Apparently there is no way to individually mark the field as read only in the service? It seems to ba an all or nothing situation.

Morton's sample is not complete enough for me to make it work. How is the value of g established? Where is the link to tell it which layer the data is coming from, etc.? Silverlight has a basic DataForm template. Can this be used and is there a sample that shows how to hook it up ?

Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
You can set layer properties and mark individual fields as read-only by following this blog post: http://blogs.esri.com/Dev/blogs/arcgisdesktop/archive/2010/09/07/Preparing-a-map-for-editing_3A00_-S...

In Morten's example, you will define a control template that binds to your graphic attributes. These binding statements will get resolved once the DataContext of that control is set, which is what the ShowAttributes() method do. You can decide which event will call ShowAttributes(). For example on MouseLeftButtonDown on the layer, you can pass e.Graphic.
0 Kudos
DonFreeman
Emerging Contributor
Thanks Jenn.
I was able to solve my immediate problem by setting the field to readonly in ArcMap and republishing the service. I had been looking for a setting in ServerManager but it was further back as you explained.

However, for my own education I would still like to understand the alternative of creating my own dataform. So how do you create a data context associated with a FeatureLayer? I have done this with a standalone table but not with a feature class. Is there a sample around somewhere? (I understand the code better than the textual description.)

And, you mention the graphic. Did you mean the layer? I don't really have a graphic anywhere except for the symbol (which btw is provided by a custom renderer.)
Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
Sure no problem. Consider this very short sample:

Xaml-code:
<Grid x:Name="LayoutRoot" Background="White">
 <esri:Map x:Name="MyMap">
  <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
  <esri:FeatureLayer OutFields="*" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown 
Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0"/>
 </esri:Map>

 <StackPanel x:Name="myAttributeEditor"  VerticalAlignment="Top" HorizontalAlignment="Right" Height="100" Width="100">
  <TextBlock x:Name="readOnlyField" Text="{Binding Attributes[type]}"/>
  <TextBox x:Name="editableField" Text="{Binding Attributes[description], Mode=TwoWay}"/>
 </StackPanel>
</Grid>


Code-behind
private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
{
 myAttributeEditor.DataContext = e.Graphic;
}


Notice that every time I select a different feature, the attribute editor changes its value. In this feature service, 'type' is editable but I've restricted editing by making it a TextBlock. The 'description' field is editable too and I've allowed editing by making it a TextBox with Two-Way binding.

To improve this you can create your own UserControl instead of just a StackPanel within the same Grid. But same idea, you set its DataContext for the Binding to be resolved. It would not know which Attributes to retrieve unless it knows the Graphic.
0 Kudos