I fielded a question this week that may help other Silverlight 4 developers working with Esri products. The question was how to add records to a table that lives inside a geodatabase. While there is probably more then one way to skin this cat, here is one way to do this if you've got the Silverlight Toolkit installed.In short, I used the Feature Service. If other people have a different implementation feel free to share.
<UserControl x:Class="StandaloneTableEditing.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
�??- note the SL toolkit package is used here �?�
<Grid x:Name="LayoutRoot" Background="White">
<Grid x:Name="MyForm">
<Grid.RowDefinitions>
<RowDefinition Height="40" ></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Silverlight Standalone Table Editing" Margin="10" FontSize="14" >
</TextBlock>
<df:DataForm x:Name="myDataForm" AutoEdit="False" CommandButtonsVisibility="All" Grid.Row="1" Width="400" Height="300" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Top" >
</df:DataForm>
</Grid>
</Grid>
</UserControl>
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;
using System.ComponentModel;
//Check to aake sure the System.ComponentModel reference has been added
namespace StandaloneTableEditing
{
public partial class MainPage : UserControl
{
public string Owner { get; set; }
public int Value { get; set; }
public string Approved { get; set; }
public int Lastupdate { get; set; }
public Inspection inspection { get; set; }
public FeatureLayer featurelayer { get; set; }
public MainPage()
{
InitializeComponent();
InitializeFeatureService();
InitializeInspection();
myDataForm.CurrentItem = inspection; // Set up data form with data using the set Inspection Class below
}
private void InitializeInspection()
{
//Set up default values
inspection = new Inspection()
{
Owner = "David Hasselhoff ",
Value = 100,
Approved = "Bay Watch",
Lastupdate = 1111,
InspectionFeatureLayer = featurelayer
};
}
public void InitializeFeatureService()
{
featurelayer = new FeatureLayer();
featurelayer.Url = "http://serverbox/ArcGIS/rest/services/EditingTables/FeatureServer/1";
featurelayer.AutoSave = false;
featurelayer.Mode = FeatureLayer.QueryMode.OnDemand;
featurelayer.Initialized += Table_IsInitialized;
featurelayer.Initialize();
featurelayer.EndSaveEdits += Insert_EndSaveEdits;
featurelayer.SaveEditsFailed += Insert_SaveEditsFailed;
}
public void Table_IsInitialized(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("it's initialized...");
}
public void Insert_SaveEditsFailed(object sender, EventArgs e)
{
string mes = e.ToString(); // For debugging
System.Diagnostics.Debug.WriteLine(mes);
}
public void Insert_EndSaveEdits(object sender, EventArgs e)
{
string mes = e.ToString(); // For debugging
System.Diagnostics.Debug.WriteLine(mes);
}
}
public class Inspection : IEditableObject
{
public string Owner { get; set; }
public int Value { get; set; }
public string Approved { get; set; }
public int Lastupdate { get; set; }
public Inspection TempInspection { get; set; }
public FeatureLayer InspectionFeatureLayer;
public void BeginEdit()
{
// Save current Values
TempInspection = new Inspection()
{
Owner = this.Owner,
Value = this.Value,
Approved = this.Approved,
Lastupdate = this.Lastupdate
};
}
public void CancelEdit()
{
// Reset Values
Owner = TempInspection.Owner;
Value = TempInspection.Value;
Approved = TempInspection.Approved;
Lastupdate = TempInspection.Lastupdate;
}
public void EndEdit()
{
ESRI.ArcGIS.Client.Graphic graphicAttribute = new ESRI.ArcGIS.Client.Graphic();
graphicAttribute.Attributes.Add("OWNER", this.Owner);
graphicAttribute.Attributes.Add("VALUE", this.Value);
graphicAttribute.Attributes.Add("APPROVED", this.Approved);
graphicAttribute.Attributes.Add("LASTUPDATE", this.Lastupdate);
InspectionFeatureLayer.Graphics.Add(graphicAttribute);
InspectionFeatureLayer.SaveEdits();
}
}
}
Regards, Doug Carroll, ESRI Support Services SDK Team http://support.esri.com/