Hi,I'm making a "clear graphics" function for my application, and i need to clear my 3 GraphicsLayers.I tried this:
private void btnLimparGraficos_click(object sender, RoutedEventArgs e)
{
foreach (ESRI.ArcGIS.Client.GraphicsLayer layer in Mapa.Layers)
{
layer.ClearGraphics();
}
}
This code has thrown this exception:
throw new Error("Unhandled Error in Silverlight Application Unable to cast object of type 'ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer' to type 'ESRI.ArcGIS.Client.GraphicsLayer'.
em MDSalvador.MainPage.btnLimparGraficos_click(Object sender, RoutedEventArgs e)
em System.Windows.Controls.Primitives.ButtonBase.OnClick()
em System.Windows.Controls.Button.OnClick()
em System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
em System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
em MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)");
This is my map:
<esri:Map x:Name="Mapa" Background="#FFC3D2E5" MouseClick="Mapa_MouseClick" ExtentChanged="Mapa_ExtentChanged" IsLogoVisible="False" Margin="0" Extent="534290.354886005,8558896.08922354,584298.229116458,8591401.20747334">
<i:Interaction.Behaviors>
<esri:ConstrainExtentBehavior ConstrainedExtent="515281.548717264,8545182.63295419,605292.978740125,8611976.82904258" />
</i:Interaction.Behaviors>
<esri:ArcGISDynamicMapServiceLayer ID="Mapa Base" ImageFormat="JPG"
/>
<esri:ArcGISDynamicMapServiceLayer ID="Ortofoto" ImageFormat="PNG8"
/>
<esri:ArcGISDynamicMapServiceLayer ID="Logradouros" ImageFormat="PNG32"
/>
<esri:ArcGISDynamicMapServiceLayer ID="Projetos Viários" ImageFormat="PNG32"
/>
<esri:ArcGISDynamicMapServiceLayer ID="Bairros" ImageFormat="PNG32"
/>
<!-- Utilizado no Desenho no Mapa - Paula Soane - 23/09/2010-->
<esri:GraphicsLayer ID="MyGraphicsLayer" />
<!-- Utilizado no Zoom por coordenadas - Jonatas Lima Povoas - 07/10/2010-->
<esri:GraphicsLayer ID="layerGraficoBuscaCoordenadas">
</esri:GraphicsLayer>
<!-- Utilizado na Busca de Bairros - Ygor Thomaz - 01/10/2010-->
<esri:GraphicsLayer ID="layerGraficosResultadosBairros" >
</esri:GraphicsLayer>
<!-- Utilizado na Busca de Logradouros - Ygor Thomaz - 20/09/2010-->
<esri:GraphicsLayer ID="layerGraficosResultadosLogradouros" >
</esri:GraphicsLayer>
</esri:Map>
So, what's the problem with my code and how can i fix it?