Hi I think it is because you are copying your graphics, but really you are just taking a reference to them and so both layers are pointing to the same collection of graphics/geometries.It looks like you need to do a deep clone of your graphics collection - or at least the geometries as I dont think they are allowed to exist in multiple GraphicsLayersReplace the following code...in class MapPrintViewViewModelreplace CreateGraphicsLayer with this method... public GraphicsLayer CreateGraphicsLayer()
{
GraphicsLayer graphicsLayer = new GraphicsLayer();
foreach (Graphic g in MapGraphics)
{
graphicsLayer.Graphics.Add(g);
}
//graphicsLayer.Graphics = MapGraphics as GraphicCollection;
return graphicsLayer;
}
in mainpage.xaml.cs replace the btnPrint_Click method with the code below... private void btnPrint_Click(object sender, RoutedEventArgs e)
{
//Initialize the view model for the map print.
MapPrintViewViewModel viewModel = new MapPrintViewViewModel();
//Get the current base map.
ArcGISTiledMapServiceLayer layer = MyMap.Layers[0] as ArcGISTiledMapServiceLayer;
viewModel.BaseMapURL = layer.Url;
//Get the current map extent.
viewModel.CurrentExtent = MyMap.Extent;
//Get a collection of visible dynamic layers.
foreach (Layer dLayer in MyMap.Layers)
{
try
{
if (dLayer is ArcGISDynamicMapServiceLayer)
{
ArcGISDynamicMapServiceLayer dynamicLayer = dLayer as ArcGISDynamicMapServiceLayer;
//If the dynamic layer is currently visible, add it to the print map.
//if (dynamicLayer.VisibleLayers != null)
if (dynamicLayer.VisibleLayers.Count() > 0)
{
//dynamicLayers.Add(dynamicLayer);
viewModel.VisibleLayers.Add(new MapPrintViewViewModel.DynamicMapLayerInformation(dynamicLayer.MapName, dynamicLayer.Url, dynamicLayer.Opacity, dynamicLayer.VisibleLayers));
}
}
}
catch { }
try
{
if (dLayer is GraphicsLayer)
{
GraphicsLayer graphicsLayer = dLayer as GraphicsLayer;
//viewModel.MapGraphics = graphicsLayer.Graphics;
foreach (Graphic g in graphicsLayer.Graphics)
{
Graphic clonedGraphic = new Graphic();
clonedGraphic.Geometry = ((ESRI.ArcGIS.Client.Geometry.Polygon)g.Geometry).Clone();
foreach (KeyValuePair<string, object> o in g.Attributes)
{
clonedGraphic.Attributes.Add(o.Key, o.Value);
}
clonedGraphic.Symbol = g.Symbol;
viewModel.MapGraphics.Add(clonedGraphic);
}
}
}
catch { }
}
MapPrintView printView = new MapPrintView();
printView.DataContext = viewModel;
printView.BuildMap();
//If there are layers to build a legend for, build the legend.
if (viewModel.VisibleLayers != null && viewModel.VisibleLayers.Count > 0)
{
printView.CreateLegend();
}
printView.Show();
}
hope this helpsregardschris