Select to view content in your preferred language

Silverlight samples from ESRI

3827
10
12-09-2010 12:11 PM
JoannaLaroussi
Emerging Contributor
I saw some great examples of Silverlight applications on ArcGIS API for Microsoft Silverlight Samples. I wanted to see code in C#, but under tab ???Code Behind C#??? is not posted all code, and when I wanted to download SDK I received an error ???the web page cannot be found???. I tried on different samples and I received always the same error. Could somebody tell me how to download a full code for sample? I am the most interested in Editing Tools ??? Explicit Save. Thank you!
0 Kudos
10 Replies
JenniferNery
Esri Regular Contributor
This is where you download the full SDK: http://help.arcgis.com/en/webapi/silverlight/help/index.html#/Sample_Interactive_SDK/01660000000v000...

When Navigating our SDK Interactive Sample page http://esriurl.com/slsdk2:
You need to select from the side menu items: Editing > Edit Tools - Explicit Save

To get to : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave

There are tab menu items you can select from (Live Sample, XAML, Code Behind C#, Code Behind VB) by default it is Live Sample.
0 Kudos
JoannaLaroussi
Emerging Contributor
Thank you for your answer! I installed SDK like you suggested and followed supplied links, but still everything what I am seeing after clicking "code behind C#" is just a few lines. Could you, please tell me where I can find the rest of the code?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;

namespace ArcGISSilverlightSDK
{
    public partial class EditToolsExplicitSave : UserControl
    {
        public EditToolsExplicitSave()
        {
            InitializeComponent();
        }

        private void CancelEditsButton_Click(object sender, RoutedEventArgs e)
        {
            Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
            foreach (GraphicsLayer graphicsLayer in editor.GraphicsLayers)
            {
                if (graphicsLayer is FeatureLayer)
                {
                    FeatureLayer featureLayer = graphicsLayer as FeatureLayer;
                    if (featureLayer.HasEdits)
                        featureLayer.Update();
                }
            }
        }


This is where you download the full SDK: http://help.arcgis.com/en/webapi/silverlight/help/index.html#/Sample_Interactive_SDK/01660000000v000...

When Navigating our SDK Interactive Sample page http://esriurl.com/slsdk2:
You need to select from the side menu items: Editing > Edit Tools - Explicit Save

To get to : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave

There are tab menu items you can select from (Live Sample, XAML, Code Behind C#, Code Behind VB) by default it is Live Sample.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
but still everything what I am seeing after clicking "code behind C#" is just a few lines. Could you, please tell me where I can find the rest of the code?

There is no more code for this sample.
Most of the work is done by the Editor control which is provided by the SL API.
0 Kudos
JoannaLaroussi
Emerging Contributor
Most of the work is done by the Editor control which is provided by the SL API.


Would you, please explain a little more? How I can use Silverlight sample about editing and Editor control to build my own web application? I am working on my first project and I am a little confuse how to make the best use of provided by ESRI resources and examples.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I suggest you start following the steps described in this 'Getting Started' video : http://help.arcgis.com/en/webapi/silverlight/help/index.html#//016600000004000000.htm

You should end up with a working silverlight application but without editing capabilities.

Then you can add editing capabilities by copying and pasting code from the interactive sample.

1) In your MainPage.xaml.cs add this code coming from the sample:
private void CancelEditsButton_Click(object sender, RoutedEventArgs e)
        {
            Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
            foreach (GraphicsLayer graphicsLayer in editor.GraphicsLayers)
            {
                if (graphicsLayer is FeatureLayer)
                {
                    FeatureLayer featureLayer = graphicsLayer as FeatureLayer;
                    if (featureLayer.HasEdits)
                        featureLayer.Update();
                }
            }
        }


2) In your MainPage.xaml add:
2.1) The editor resource
       <Grid.Resources>
            <esri:Editor x:Key="MyEditor" 
                         Map="{Binding ElementName=MyMap}" 
                         LayerIDs="ThreatAreas"   
                         GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"
                             />
        </Grid.Resources>


2.2) The FeatureLayer to edit
 <esri:FeatureLayer ID="ThreatAreas"  
                               Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer..."                  
                               AutoSave="False" 
                               Mode="OnDemand" 
                               ValidateEdits="True" 
                               DisableClientCaching="True" />


2.3) The whole panel with the editor tools:
 
<Border Background="#FF919191" BorderThickness="1" CornerRadius="5"
             HorizontalAlignment="Right"  VerticalAlignment="Top"
             Padding="5" BorderBrush="Black" Margin="0,5,5,0"
                DataContext="{StaticResource MyEditor}">
            <StackPanel x:Name="EditorTools" 
                        Orientation="Vertical">
                <StackPanel Orientation="Horizontal">
                    <Button x:Name="AddButton" Margin="2"
                         ToolTipService.ToolTip="Fire"
                         Content="Add Polygon" 
                         Command="{Binding Add}">
                        <Button.CommandParameter>
                            <sys:Int32>10301</sys:Int32>
                        </Button.CommandParameter>
                    </Button>
                    <Button x:Name="SelectButton" Margin="2"                            
                            Command="{Binding Select}" 
                            CommandParameter="New" >
                        <TextBlock>New<LineBreak/>Selection</TextBlock>
                    </Button>
                    <Button x:Name="AddSelectButton" Margin="2"                            
                            Command="{Binding Select}" 
                            CommandParameter="Add">
                        <TextBlock>Add to<LineBreak/>Selection</TextBlock>
                    </Button>
                    <Button x:Name="RemoveSelectButton" Margin="2"                             
                            Command="{Binding Select}"
                            CommandParameter="Remove" >
                        <TextBlock>Remove from<LineBreak/>Selection</TextBlock>
                    </Button>
                    <Button x:Name="ClearSelectionButton" Margin="2"                            
                            Command="{Binding ClearSelection}">
                        <TextBlock>Clear<LineBreak/>Selection</TextBlock>
                    </Button>
                    <Button x:Name="DeleteButton" Margin="2"                           
                            Command="{Binding DeleteSelected}">
                        <TextBlock>Delete<LineBreak/>Selected</TextBlock>
                    </Button>
                    <Button x:Name="CancelButton" Margin="2"                           
                            Command="{Binding CancelActive}">
                        <TextBlock>Cancel<LineBreak/>Action</TextBlock>
                    </Button>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Button x:Name="EditVerticesButton" Margin="2"                        
                         Command="{Binding EditVertices}">
                        <TextBlock>Edit Vertices<LineBreak/>/Move Selected</TextBlock>
                    </Button>
                    <Button x:Name="CutButton" Margin="2"                            
                            Command="{Binding Cut}">
                        <TextBlock>Cut<LineBreak/>Selected</TextBlock>
                    </Button>
                    <Button x:Name="ReshapeButton" Margin="2"                           
                            Command="{Binding Reshape}">
                        <TextBlock>Reshape<LineBreak/>Selected</TextBlock>
                    </Button>
                    <Button x:Name="UnionButton" Margin="2"                           
                            Command="{Binding Union}">
                        <TextBlock>Union<LineBreak/>Selected</TextBlock>
                    </Button>
                    <Button x:Name="SaveButton" Margin="2"                           
                            Command="{Binding Save}">
                        <TextBlock FontWeight="Bold">Save<LineBreak/>Edits</TextBlock>
                    </Button>
                    <Button x:Name="CancelEditsButton" Margin="2" 
                            IsEnabled="{Binding ElementName=MyMap, Path=Layers[ThreatAreas].HasEdits}"
                            Click="CancelEditsButton_Click" >
                        <TextBlock FontWeight="Bold">Cancel<LineBreak/>Edits</TextBlock>
                    </Button>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <CheckBox x:Name="FreehandCheckBox" VerticalAlignment="Center" Margin="2"
                          IsChecked="{Binding Path=Freehand, Mode=TwoWay}" 
                          Content="Freehand Draw" />
                    <CheckBox x:Name="AutoCompleteCheckBox" VerticalAlignment="Center" Margin="2"
                          IsChecked="{Binding Path=AutoComplete, Mode=TwoWay}" 
                          Content="Auto Complete" />
                    <CheckBox x:Name="AutoSelectCheckBox" VerticalAlignment="Center" Margin="2"
                          IsChecked="{Binding Path=AutoSelect, Mode=TwoWay}" 
                          Content="Auto Select" />
                    <CheckBox x:Name="ContinuousCheckBox" VerticalAlignment="Center" Margin="2"
                          IsChecked="{Binding Path=ContinuousMode, Mode=TwoWay}" 
                          Content="Continuous Action" />
                </StackPanel>
            </StackPanel>
        </Border>


You should get an application with editing capabilities.
0 Kudos
JoannaLaroussi
Emerging Contributor
Thanks a lot!
0 Kudos
JudyTroutwine
Regular Contributor
Please tell me the CommandParameter value to use for "Add" when adding points.
0 Kudos
JayKappy
Frequent Contributor
Is there a different Command Parameter for Point, Line, Polygon?????
If so what are they?

PLEASE HELP!  Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
In this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave

The following XAML-code for Add button is specific to the service: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer.... (See Types section).
<Button Command="{Binding Add}" Content="Add Polygon" Margin="2"                        
                         ToolTipService.ToolTip="Civil Disturbance">
                        <Button.CommandParameter>
                            <sys:Int32>10101</sys:Int32>
                        </Button.CommandParameter>
                    </Button>


When dealing with FeatureLayer, Add.CommandParameter is expected to be a FeatureType (defined by service). When dealing with GraphicsLayer, Add.CommandParameter is expected to be a symbol (matching geometry).
0 Kudos