<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(); } } }
var graphic = new Graphic(); if (l.LayerInfo == null) return; //use LayerInfo.Fields foreach (var field in l.LayerInfo.Fields) graphic.Attributes[field.Name] = null; //use PrototypeAttributes FeatureTemplate featureTemplate = null; if (l.LayerInfo.Templates != null && l.LayerInfo.Templates.Count > 0) featureTemplate = l.LayerInfo.Templates.FirstOrDefault().Value; else if (l.LayerInfo.FeatureTypes != null && l.LayerInfo.FeatureTypes.Count > 0) { var featureType = l.LayerInfo.FeatureTypes.FirstOrDefault(); if (featureType.Value != null && featureType.Value.Templates != null) featureTemplate = featureType.Value.Templates.FirstOrDefault().Value; } if (featureTemplate != null && featureTemplate.PrototypeAttributes != null) { foreach (var item in featureTemplate.PrototypeAttributes) graphic.Attributes[item.Key] = item.Value; }
When adding a new graphic to your FeatureLayer (Table), you may need to set default values to its attributes before setting FeatureDataForm.GraphicSource property.
You can use LayerInfo.Fields or FeatureTemplate.PrototypeAttributes, the following will be available after the layer has been initialized:var graphic = new Graphic(); if (l.LayerInfo == null) return; //use LayerInfo.Fields foreach (var field in l.LayerInfo.Fields) graphic.Attributes[field.Name] = null; //use PrototypeAttributes FeatureTemplate featureTemplate = null; if (l.LayerInfo.Templates != null && l.LayerInfo.Templates.Count > 0) featureTemplate = l.LayerInfo.Templates.FirstOrDefault().Value; else if (l.LayerInfo.FeatureTypes != null && l.LayerInfo.FeatureTypes.Count > 0) { var featureType = l.LayerInfo.FeatureTypes.FirstOrDefault(); if (featureType.Value != null && featureType.Value.Templates != null) featureTemplate = featureType.Value.Templates.FirstOrDefault().Value; } if (featureTemplate != null && featureTemplate.PrototypeAttributes != null) { foreach (var item in featureTemplate.PrototypeAttributes) graphic.Attributes[item.Key] = item.Value; }
When adding a new graphic to your FeatureLayer (Table), you may need to set default values to its attributes before setting FeatureDataForm.GraphicSource property.
You can use LayerInfo.Fields or FeatureTemplate.PrototypeAttributes, the following will be available after the layer has been initialized:var graphic = new Graphic(); if (l.LayerInfo == null) return; //use LayerInfo.Fields foreach (var field in l.LayerInfo.Fields) graphic.Attributes[field.Name] = null; //use PrototypeAttributes FeatureTemplate featureTemplate = null; if (l.LayerInfo.Templates != null && l.LayerInfo.Templates.Count > 0) featureTemplate = l.LayerInfo.Templates.FirstOrDefault().Value; else if (l.LayerInfo.FeatureTypes != null && l.LayerInfo.FeatureTypes.Count > 0) { var featureType = l.LayerInfo.FeatureTypes.FirstOrDefault(); if (featureType.Value != null && featureType.Value.Templates != null) featureTemplate = featureType.Value.Templates.FirstOrDefault().Value; } if (featureTemplate != null && featureTemplate.PrototypeAttributes != null) { foreach (var item in featureTemplate.PrototypeAttributes) graphic.Attributes[item.Key] = item.Value; }
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/
var l = new FeatureLayer() { Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1", Where = "1=1" }; l.OutFields.Add("*"); MyDataGrid.GraphicsLayer = l; l.Initialized += (s, e) => { l.Update(); }; l.Initialize();
Sure, you can bind FeatureDataGrid.GraphicsLayer to a GraphicsLayer that stores results from your QueryTask. FeatureDataForm only works against FeatureLayer, so in that case you need to do the query on FeatureLayer itself. But FeatureLayer does not necessarily have to be tied to a map, as this does not make sense for tables without geometry in the data.
Here's an example:You can update: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid
After removing binding statements in XAMl for FDG.Map and FDG.GraphicsLayer, they can do something like this.
var l = new FeatureLayer() { Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1", Where = "1=1" }; l.OutFields.Add("*"); MyDataGrid.GraphicsLayer = l; l.Initialized += (s, e) => { l.Update(); }; l.Initialize();
You can update l.Where and call l.Update() (similar to running a query). When working with GraphicsLayer, you simply add features from Query_ExecuteCompleted event to your GraphicsLayer and FDG will pickup the Graphics.Attributes. Adding/removing graphics on the layer, should affect FDG. You can also apply FilterSource and do something like FDG.FilterSource = MyGraphicsLayer.Graphics.Where (g => (string) g.Attributes["status"] == "new").ToList(). Using Linq query or QueryTask, you can change the content of FDG.