Select to view content in your preferred language

Editing in WPF Example

4220
5
10-28-2010 06:43 PM
SteveVidal
Emerging Contributor
Hi,

Is ESRI going to release a sample for WPF that is comparable to the Silverlight example??

We are rolling out a massive WPF application and would like to examine the samples for editing, time aware layers etc. all shown and demonstrated on silverlight example app.

cheers
steve
0 Kudos
5 Replies
SteveVidal
Emerging Contributor
Hi Adding to above,

A C# source code example of adding a point, line or polygon to a feature layer in C# would be great - a bit like the Silverlight example but it would be great to see the example mainly written in C# rather than XAML.
0 Kudos
JenniferNery
Esri Regular Contributor
When you go to the Interactive SDK http://esriurl.com/slsdk2 and click Download SDK on the upper right corner, you will see that there is a WPF SDK. It should have similar content except for some platform differences. There's also a sample on adding graphics in code: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddGraphics

Basically, these are equivalent:
XAML:
                        <esri:Graphic>
                            <esri:MapPoint X="-80.210" Y="35.284" />
                        </esri:Graphic>

                        <esri:Graphic>
                            <esri:Polyline >
                                <esri:Polyline.Paths>
                                    <esri:PointCollection>
                                        <esri:MapPoint X="-118.169" Y="34.016" />
                                        <esri:MapPoint X="-104.941" Y="39.7072" />
                                        <esri:MapPoint X="-96.724" Y="32.732" />
                                        <esri:MapPoint X="-87.671" Y="41.804" />
                                        <esri:MapPoint X="-74" Y="40.68" />
                                    </esri:PointCollection>
                                </esri:Polyline.Paths>
                            </esri:Polyline>
                        </esri:Graphic>

                        <esri:Graphic>
                            <esri:Polygon >
                                <esri:Polygon.Rings>
                                    <esri:PointCollection>
                                        <esri:MapPoint X="110.039" Y="-20.303" />
                                        <esri:MapPoint X="132.539" Y="-7.0137" />
                                        <esri:MapPoint X="153.281" Y="-13.923" />
                                        <esri:MapPoint X="162.773" Y="-35.174" />
                                        <esri:MapPoint X="133.594" Y="-43.180" />
                                        <esri:MapPoint X="111.797" Y="-36.032" />
                                        <esri:MapPoint X="110.039" Y="-20.303" />
                                    </esri:PointCollection>
                                </esri:Polygon.Rings>
                            </esri:Polygon>
                        </esri:Graphic>


   Graphic point = new Graphic() { Geometry = new MapPoint(-80.210, 35.284) };

   PointCollection pts = new PointCollection();
   pts.Add(new MapPoint(-118.169, 34.016));
   pts.Add(new MapPoint(-104.941, 39.7072));
   pts.Add(new MapPoint(-96.724, 32.732));
   pts.Add(new MapPoint(-87.671, 41.804));
   pts.Add(new MapPoint(-74, 40.68));
   Polyline polyline = new Polyline();
   polyline.Paths.Add(pts);
   Graphic line = new Graphic() { Geometry = polyline };

   pts = new PointCollection();
   pts.Add(new MapPoint(110.039, -20.303));
   pts.Add(new MapPoint(132.539, -7.0137));
   pts.Add(new MapPoint(153.281, -13.923));
   pts.Add(new MapPoint(162.773, -35.174));
   pts.Add(new MapPoint(133.594, -43.180));
   pts.Add(new MapPoint(111.797, -36.032));
   pts.Add(new MapPoint(110.039, -20.303));
   Polygon polygon = new Polygon();
   polygon.Rings.Add(pts);
   Graphic area = new Graphic() { Geometry = polygon };
0 Kudos
SteveVidal
Emerging Contributor
Thanks so much. Appreciate your help.

I was really after a c# snippet that updated a point or polyline or polgon feature service on ArcGIS v10 server through c# code for a particular feature layer.

I am struggling to understand the Editor class in C# for the v2.0 or v2.1 WPF dll's.

An example might be:

I want to add a new "Task" point which has 5 corresponding attributes.  Within SDE the Task Feature class has been defined and versioned, is within a MXD and published with feature access / editing capabilities.  I can edit in ArcMap but not through c# .Net Framework 3.5 code.

The examples that I can find the XAML always reference an editor ID  and seem to want to use a geometryURL?  but I only have a dynamic map and map that has been exposed as a feature access map.

Any c# code to add a new point, update the attributes associated with the feature would be most appreciated.

Thanks so so much
0 Kudos
MarioVernari
Emerging Contributor
I agree.
The layer classes should be derived from an ItemsControl or, at least, from a Panel.
Better: the layer classes should expose only a datamodel, which can be stylable on any WPF/SL control.
Cheers

To the ESRI Team: think about giving the APIs source as open...
0 Kudos
JenniferNery
Esri Regular Contributor
The Editor, EditorWidget, TemplatePicker use GeometryService to add/edit polyline and polygon features.  It is used to simplify, auto select, auto complete, cut, reshape, union, etc. Here's some documentation about it: http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/geometryserver.html

If your feature service only contain points, you can still use the Editor, EditorWidget, TemplatePicker without specifying GeometryService.  You can use just the TemplatePicker to add points and set its ShowAttributesOnAdd to true to enable FeatureDataForm to show after the graphic is added to your map. http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitTemplatePicker

I suggest that you take advantage of the TemplatePicker and FeatureDataForm because this requires no extra coding on your part, adding TemplatePicker in the XAML should be sufficient.

If however, you still prefer to add the point in code, you can still do so. When you create your graphic, you need to set its Geometry and Attributes before adding to your layer. 

If you know the FeatureType, you can get the Template corresponding to that type from FeatureLayer.LayerInfo.FeatureTypes[].Templates.http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureSer... . PrototypeAttributes will give you the default attribute key-value pair for the specific type. You also have access to FeatureLayer.LayerInfo.Fields http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Field_memb.... This will determine what acceptable values are for each field.  All these checks are done by TemplatePicker and FeatureDataForm but it certainly is not impossible to navigate your way around doing this in code.
0 Kudos