For each item in the legend If layer is a raster: do nothing; Else Add it to the legend
Solved! Go to Solution.
<esri:Legend Map="{Binding ElementName=MyMap}" LayerIDs="Points of Interest, United States" LayerItemsMode="Tree" ShowOnlyVisibleLayers="False" Refreshed="Legend_Refreshed">private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e) { // If a map layer has sublayers, iterate through them. if (e.LayerItem.LayerItems != null) { // Iterate through all the sublayer items. foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems) { // Remove the layer other than Feature layer. if (layerItemVM.LayerType != "Feature Layer") e.LayerItem.LayerItems.Remove(layerItemVM); } } <esri:Legend Map="{Binding ElementName=MyMap}" LayerIDs="Points of Interest, United States" LayerItemsMode="Tree" ShowOnlyVisibleLayers="False" Refreshed="Legend_Refreshed">private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e) { // If a map layer has sublayers, iterate through them. if (e.LayerItem.LayerItems != null) { // Iterate through all the sublayer items. foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems) { // Remove the layer other than Feature layer. if (layerItemVM.LayerType != "Feature Layer") e.LayerItem.LayerItems.Remove(layerItemVM); } }
In Xaml include the refreshed event (replace the map, layerIDS):
<esri:Legend Map="{Binding ElementName=MyMap}" LayerIDs="Points of Interest, United States" LayerItemsMode="Tree" ShowOnlyVisibleLayers="False" Refreshed="Legend_Refreshed">
<StackPanel x:Name="LegendPanel" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Top">
<StackPanel.Resources>
<DataTemplate x:Key="SymbolTreeNode">
<StackPanel Orientation="Horizontal" Margin="0,-2,0,-2">
<Image Source="{Binding ImageSource}" Stretch="None" Width="36" Margin="0,0,0,0"></Image>
<TextBlock Text="{Binding Label}" Margin="4,0,0,0" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</DataTemplate>
</StackPanel.Resources>
</StackPanel>
foreach (LegendItemInfo legItem in (List<LegendItemInfo>)treeNode.ItemsSource)
{
if (legItem.ImageSource != null)
itemLabel = (((List<LegendItemInfo>)treeNode.ItemSource.Count -- 1) ?
layerName : legItem.Label;
if (itemLabel.Contains(removed content)
{ legendItem.Add(new LegendItemInfo() { ImageSource = legItem.ImageSource, Label = itemLabel });
}
}
}