Capture layer turn off event

636
2
Jump to solution
04-05-2013 05:39 AM
LuisGarcia2
Occasional Contributor II
Let me start by explaining my business issue. I have two Graphics layer on a map, one of them has the graphics I want to show, the other one has TextSymbol as symbols and shows as a label of the graphics in the first layer (see the attachment for clarification). So, now let's say the user turns off the graphics layer, then the "labels layer" will still be turned on, so that looks awkward. So basically I would like the "labels layer" to be turned off in the same event when the graphics are turned off. 

Ok, so here is the technical stuff. I have a Legend added to my map where the users can turn the layers on and off:

 <esri:Legend Name="legend1" Map="{Binding ElementName=map1}" LayerItemsMode="Tree" ShowOnlyVisibleLayers="False" FontSize="11" Refreshed="legend1_Refreshed">                 <esri:Legend.MapLayerTemplate>                     <DataTemplate>                         <StackPanel Orientation="Horizontal">                             <CheckBox Content="{Binding Label}"                   IsChecked="{Binding IsEnabled, Mode=TwoWay}"                   IsEnabled="{Binding IsInScaleRange}">                             </CheckBox>                             <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />                         </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>              </esri:Legend>


So, this is what I need help with. What I'd like to do is capture the event that turns the layers on and off. I guess that would be for the CheckBox?? Or can I capture it in the layer per se?? So, say that I extend the layer and interesect the event there??

Thanks!
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
The easiest way to achieve this is likely to do it out of the legend control.

For your 2 layers, subscribe to the event PropertyChanged and if the property 'Visible' changed, change the visibility of the other layer accordingly.

View solution in original post

0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
The easiest way to achieve this is likely to do it out of the legend control.

For your 2 layers, subscribe to the event PropertyChanged and if the property 'Visible' changed, change the visibility of the other layer accordingly.
0 Kudos
LuisGarcia2
Occasional Contributor II
Right on! That solves the problem. Thanks Dominique!
0 Kudos