#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;
// }
// }
//}
}
}
#endregion
private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
foreach (var item in e.AddedItems)
{
var g = GetGraphicSibling(item);
if (g.Layer is FeatureLayer)
{
MyAttachmentEditor.FeatureLayer = g.Layer 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;
}
Yes this code should replace your FeatureDataGrid_SelectionChange event handler. This is how you can get the graphic from FDG.row. Once you have the graphic, you can set AttachmentEditor.GraphicSource property.
MyAttachmentEditor.FeatureLayer = g.Layer as FeatureLayer; MyAttachmentEditor.GraphicSource = g;
Try debugging to your code to check if AttachmentEditor.FeatureLayer and AttachmentLayer.GraphicsSource get set properly. You can also check if the FeatureLayer..LayerInfo.HasAttachments is True. It could be that the service does not support attachments.
void EditorWidget_EditCompleted(object sender, Editor.EditEventArgs e)
{
if (e.Action == Editor.EditAction.ClearSelection) //|| e.Action == Editor.EditAction.Select
{
MyAttachmentEditor.GraphicSource = null;
}
if (e.Action == Editor.EditAction.Add || e.Action == Editor.EditAction.Select)
{
foreach (var edit in e.Edits)
{
if (edit.Layer is FeatureLayer)
{
if (e.Action == Editor.EditAction.Add || edit.Graphic.Selected)
{
MyAttachmentEditor.FeatureLayer = edit.Layer as FeatureLayer;
MyAttachmentEditor.GraphicSource = edit.Graphic;
}
}
}
}
}
foreach (var item in e.AddedItems)
{
var g = GetGraphicSibling(item);
if (g.Layer is FeatureLayer)
{
MyAttachmentEditor.FeatureLayer = g.Layer as FeatureLayer;
MyAttachmentEditor.GraphicSource = g;
}
}
private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var fdg = sender as ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid;
var g = e.AddedItems.Cast<object>().Select(GetGraphicSibling).FirstOrDefault() ??
fdg.SelectedGraphics.Where(s => !e.RemovedItems.Cast<object>().Select(GetGraphicSibling).Contains(s)).FirstOrDefault();
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;
}
{
if (MyActiveLayer.SelectedIndex == 2 || (MyActiveLayers.SelectedIndex == 3) // Layer is none Editable Feature Layer, without attachments
{
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;
}
MyFeatureDataGrid.GraphicsLayer = graphicsLayer;
graphicsLayer.Graphics.Insert(0, feature);
}
}
if ((MyActiveLayers.SelectedIndex == 0 || (MyActiveLayers.SelectedIndex == 1) // Layer is a Editable Feature Layer, has attachments
{
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;
}
}
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);
if (g.Layer is FeatureLayer)
{
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;
}
graphicsLayer.Graphics.Insert(0, feature); FeatureLayer featurelayer = graphicsLayer as FeatureLayer; MyFeatureDataGrid.GraphicsLayer = featurelayer;
MyFeatureDataGrid.GraphicsLayer = feature.Layer as FeatureLayer;