#region AttachmentLinking
private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var graphics = (sender as ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid).SelectedGraphics;
//foreach (Graphic feature in graphics)
foreach (var g in graphics)
{
//// get id
//var id = g.Attributes["PICS"];
//// TODO: retrieve outside data for this id
//HYPERIDPASS.Text = string.Format("{0}", id);
//break;
//foreach (var edit in e.Edits)
//{
//if (feature.Attributes is FeatureLayer)
//{
// //if (e.Action == Editor.EditAction.Add || edit.Graphic.Selected)
//{
if (_lastGraphic != null)
_lastGraphic.UnSelect();
g.Select();
if (g.Selected)
QueryDetailsDataGrid.ScrollIntoView(g, null);
_lastGraphic = g;
// MyAttachmentEditor.FeatureLayer = feature.Attributes as FeatureLayer;
MyAttachmentEditor.FeatureLayer = graphics as FeatureLayer;
MyAttachmentEditor.GraphicSource = g;
// MyAttachmentEditor.GraphicSource = g.Graphic;
// }
// }
//}
}
}
#endregionI think you can replace this codegraphicsLayer.Graphics.Insert(0, feature); FeatureLayer featurelayer = graphicsLayer as FeatureLayer; MyFeatureDataGrid.GraphicsLayer = featurelayer;
withMyFeatureDataGrid.GraphicsLayer = feature.Layer as FeatureLayer;
It should display features from the Editable FeatureLayer. You need not add them to another GraphicsLayer.
foreach (Graphic feature in featureSet.Features)
{
switch (featureSet.GeometryType.ToString())
{
case "Polygon":
feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
break;
case "Polyline":
feature.Symbol = LayoutRoot.Resources["CustomGrowLineSymbol"] as LineSymbol;
break;
case "Point":
feature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;
break;
}
graphicsLayer.Graphics.Insert(0, feature);
}
FeatureLayer featurelayer = graphicsLayer as FeatureLayer;
MyFeatureDataGrid.GraphicsLayer = featurelayer;
}
editor.EditCompleted += (s, e) =>
{
if (e.Action == Editor.EditAction.Select)
{
foreach (var edit in e.Edits)
{
var g = edit.Graphic;
if (g.Selected)
{
var l = edit.Layer as FeatureLayer;
MyFeatureDataGrid.GraphicsLayer = l;
}
}
}
};
<Button Command="{Binding Select}" Margin="2" DataContext="{StaticResource MyEditor}"
CommandParameter="New" Content="New"/>
private void Editor_EditCompleted(object sender, Editor.EditEventArgs e)
{
MyEditor.EditCompleted += (s, ed) => //Change e to ed
{
if (e.Action == Editor.EditAction.Select)
{
foreach (var edit in e.Edits)
{
var g = edit.Graphic;
if (g.Selected)
{
var l = edit.Layer as FeatureLayer;
MyFeatureDataGrid.GraphicsLayer = l;
}
}
}
MyFeatureDataGridWindow.IsExpanded = true;
};
}
private void SelectRectangle_Click(object sender, RoutedEventArgs e)
{
if (MyActiveLayer.SelectedIndex != 1)
{
// SelectPoints.Command = MyEditor.CancelActive;
SelectPoints.Command = MyEditor.ClearSelection;
MyEditor.SelectionMode = DrawMode.None;
MyDrawSurface.DrawMode = DrawMode.Rectangle;
MyDrawSurface.IsEnabled = (MyDrawSurface.DrawMode != DrawMode.None);
}
if (MyActiveLayer.SelectedIndex == 1)
{
Editor MyEditor = LayoutRoot.Resources["MyEditor"] as Editor;
string[] myLayerIDs = { "BirdSightings" };
MyEditor.LayerIDs = myLayerIDs;
MyEditor.SelectionMode = DrawMode.Rectangle;
MyEditor.ContinuousMode = false;
SelectPoints.CommandParameter = SelectionMode.Multiple;
// SelectPoints.CommandParameter = MyEditor.Add;
SelectPoints.Command = MyEditor.Select;
// SelectPoints.Command = new
}
}
Jennifer thanks for all the replies!
A problem that I'm running into is if I do a simple query on a dynamic service so the first if statement is allowed if (Layers.SelectedIndex != 1) - the right draw mode happens and the layer is queried, a graphic layer is created and my featuregrid is populated but then the button becomes inactive and I can't use it again, I'm not sure why this is happening.
MyEditor.EditCompleted += (s, ed) => //Change e to ed
private void SelectPoints_Click(object sender, RoutedEventArgs e)
{
if (Layers.SelectedIndex != 1)
{
// SelectPoints.Command = MyEditor.CancelActive;
SelectPoints.Command = MyEditor.ClearSelection;
MyEditor.SelectionMode = DrawMode.None;
MyDrawSurface.DrawMode = DrawMode.Rectangle;
MyDrawSurface.IsEnabled = (MyDrawSurface.DrawMode != DrawMode.None);
}
private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var fdg = sender as ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid;
foreach (var item in e.AddedItems)
{
var g = GetGraphicSibling(item);
MyAttachmentEditor.FeatureLayer = fdg.GraphicsLayer as FeatureLayer;
MyAttachmentEditor.GraphicSource = g;
}
}
private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var fdg = sender as ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid;
foreach (var item in e.AddedItems)
{
var g = GetGraphicSibling(item);
MyAttachmentEditor.FeatureLayer = fdg.GraphicsLayer as FeatureLayer;
MyAttachmentEditor.GraphicSource = g;
}
}
private static Graphic GetGraphicSibling(object item)
{
if (item != null)
{
MethodInfo mi = item.GetType().GetMethod("GetGraphicSibling");
if (mi != null)
{
return mi.Invoke(item, null) as Graphic;
}
}
return null;
}
private void SelectPoints_Click(object sender, RoutedEventArgs e)
{
if (Layers.SelectedIndex != 1)
{
// SelectPoints.Command = MyEditor.CancelActive;
SelectPoints.Command = MyEditor.ClearSelection;
MyEditor.SelectionMode = DrawMode.None;
MyDrawSurface.DrawMode = DrawMode.Rectangle;
MyDrawSurface.IsEnabled = (MyDrawSurface.DrawMode != DrawMode.None);
}
private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var fdg = sender as ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid;
foreach (var item in e.AddedItems)
{
var g = GetGraphicSibling(item);
MyAttachmentEditor.FeatureLayer = fdg.GraphicsLayer as FeatureLayer;
MyAttachmentEditor.GraphicSource = g;
}
}
private void MyEditor_EditCompleted(object sender, Editor.EditEventArgs e)
{
MyEditor.EditCompleted += (s, ed) => //Change e to ed
{
if (e.Action == Editor.EditAction.Select)
{
foreach (var edit in e.Edits)
{
var g = edit.Graphic;
if (g.Selected)
{
var l = edit.Layer as FeatureLayer;
QueryDetailsDataGrid.GraphicsLayer = l;
}
}
}
ResultsDisplay.IsExpanded = true;
};
}
I am a little bit confused with SelectPoints_Click. If you are using Editor.Select, you don't have to add a click event. The Select command will just work. You can try this SDK sample: http://help.arcgis.com/en/webapi/sil...lsExplicitSave. If you check Continuous Action check box, this sets Editor.ContinuousMode=True, which means any active command will remain active until you cancel it explicitly using CancelActive or another command gets activated. This should help you make continuous selection.
private void SelectPoints_Click(object sender, RoutedEventArgs e)
{
if (Layers.SelectedIndex != 1)
{
// SelectPoints.Command = MyEditor.CancelActive;
SelectPoints.Command = MyEditor.ClearSelection;
MyEditor.SelectionMode = DrawMode.None;
MyDrawSurface.DrawMode = DrawMode.Rectangle;
MyDrawSurface.IsEnabled = (MyDrawSurface.DrawMode != DrawMode.None);
}
if (Layers.SelectedIndex == 1)
{
Editor MyEditor = LayoutRoot.Resources["MyEditor"] as Editor;
//Clear Selection Mode
MyEditor.SelectionMode = DrawMode.None;
string[] myLayerIDs = { "MYLINES" };
MyEditor.LayerIDs = myLayerIDs;
MyEditor.SelectionMode = DrawMode.Rectangle;
MyEditor.ContinuousMode = false;
SelectPoints.CommandParameter = SelectionMode.Multiple;
// SelectPoints.CommandParameter = MyEditor.Add;
SelectPoints.Command = MyEditor.Select;
// SelectPoints.Command = new
}
}