<esri:Legend x:Name="mapLegend" Map="{Binding ElementName=MyMap}"
LayerItemsMode="Tree"
ShowOnlyVisibleLayers="False"
Refreshed="Legend_Refreshed">
<esri:Legend.MapLayerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
</StackPanel>
</DataTemplate>
</esri:Legend.MapLayerTemplate>
<esri:Legend.LayerTemplate>
<DataTemplate>
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
</DataTemplate>
</esri:Legend.LayerTemplate>
/* THE CODE IS FINE UNTIL HERE: I get a nice legend with 3 different markers and their proper Label. */
<esri:Legend.LegendItemTemplate>
<DataTemplate>
<CheckBox>
/* HERE IS MY PROBLEM: It places the red marker 3 times, while ignoring the other markers */
</CheckBox>
</DataTemplate>
</esri:Legend.LegendItemTemplate>
</esri:Legend>
<esri:Legend.LegendItemTemplate>
<DataTemplate>
<CheckBox>
/* HERE IS MY PROBLEM: It places the red marker 3 times, while ignoring the other markers */
</CheckBox>
</DataTemplate>
</esri:Legend.LegendItemTemplate>
<esri:Legend.LegendItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,-1">
<CheckBox VerticalAlignment="Center" />
<Image Source="{Binding ImageSource}" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" MinWidth="20" />
<TextBlock Text="{Binding Label}" Margin="5,0,0,0" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</esri:Legend.LegendItemTemplate><Image Source="{Binding ImageSource}" ... />Turning on/off individual LegendItems or changing their opacity is not possible on any Layer type. It is possible to get creative and perform TOC style user interactions at the Legend.LegendItemtemplate level by discovering the parent objects of individual LegendItems.
Thanks Dominique!
It works well. I am impressed.
And this is precisely the approach I will take with the C# code: I will capture the event fired by the checkbox of each item; thus, turn on/off this feature service features on its own attributes. The API documentation has good clues on how to achieve this, unless you are aware of any other approach.