<esri:Legend x:Name="mapLegend" Background="White" Width="Auto"
LayerItemsMode="Tree" ShowOnlyVisibleLayers="False"
Refreshed="Legend_Refreshed" HorizontalAlignment="Left">
<esri:Legend.MapLayerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Image Source="/Neolant.TORIS.WebClient;component/Images/mapservice.png" Margin="0,0,2,0"
VerticalAlignment="Center" Width="20" Height="20"/>
<TextBlock Text="{Binding Label}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</esri:Legend.MapLayerTemplate>
<esri:Legend.LayerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<StackPanel.Resources>
<Image x:Name="imgLayerItem"
Source="/Neolant.TORIS.WebClient;component/Images/layer.png" Margin="0,0,2,0"
VerticalAlignment="Center" Width="20" Height="20" />
<TextBlock Text="{Binding Label}" VerticalAlignment="Center" HorizontalAlignment="Center"
Margin="0,0,0,0"/>
</StackPanel>
</DataTemplate>
</esri:Legend.LayerTemplate>
</esri:Legend>
private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
{
if (e.LayerItem.LayerItems == null) return;
foreach (var layerItem in e.LayerItem.LayerItems)
{
if (layerItem.IsGroupLayer)
layerItem.ImageSource = new BitmapImage(new Uri("/Neolant.TORIS.WebClient;component/Images/group.png", UriKind.Relative));
else
layerItem.ImageSource = new BitmapImage(new Uri("/Neolant.TORIS.WebClient;component/Images/layer.png", UriKind.Relative));
}
// Note you could also set the ImageSource of e.LayerItem itself (e.g. depending on the type of map service), and you would have to change the MapLayerTemplate as well
}Note : if you have more than one possible level of group layers, you'll have to enhance the code to go down the legend tree hierarchy- Made recursive method for this!
just made it! everything works fine! thanks a lot!
- Made recursive method for this!