Select to view content in your preferred language

Right Click event for Legend Controls layers and sublayers

802
2
09-16-2011 01:54 PM
TerryGiles
Frequent Contributor
I'd like to alter my legend control so that the user can right click on a map service or a layer within a map service, get a context menu with a "What's this?" option which will return the Service or Layer description from the map service (via webclient.downloadstringasynch()...).  I've done similar things with TreeView controls in the past but they have an actual RightMouseButtonDown event - LayerItemViewModels do not as far as I can see.  Is it possible to wire a mouse event to the Legend's controls?  If so, can I get a hint in the right direction?  Thanks,

Terry
0 Kudos
2 Replies
JohnnyPenet
Emerging Contributor
Terry,

You can do the job with the interaction triggers. You will need to install the Blend SDK kit to have access to the interaction triggers. Use EventName="MouseRightButtonDown" as the event.

        <esri:Legend x:Name="LayerLegend" LayerItemsMode="Tree" ShowOnlyVisibleLayers="False"
                     Map="{Binding MapView}" Margin="0" Height="400">
            <esri:Legend.MapLayerTemplate>
                <DataTemplate>
                            <StackPanel>
                            <CheckBox Content="{Binding Label}"
                                 IsChecked="{Binding IsEnabled,Mode=TwoWay}"
                                 IsEnabled="{Binding IsInScaleRange}"
                                  >
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Clicked">
                                        <i:InvokeCommandAction CommandParameter="{Binding Label}"
                                            Command="{Binding ElementName=LayoutRoot,Path=DataContext.LayerClicked}">
                                        </i:InvokeCommandAction>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                        </CheckBox>
                        </StackPanel>
                    </DataTemplate>
            </esri:Legend.MapLayerTemplate>
            <esri:Legend.LayerTemplate>
                <DataTemplate>
                    <CheckBox Content="{Binding Label}"
                              IsChecked="{Binding IsEnabled,Mode=TwoWay}"
                              IsEnabled="{Binding IsInScaleRange}"
                              >
                    </CheckBox>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Clicked">
                                <i:InvokeCommandAction CommandParameter="{Binding Label}" >
                                    <bind:BindingHelper.Binding>
                                        <bind:RelativeSourceBinding Path="LayerClicked"
                                                                        TargetProperty="Command"
                                                                        RelativeMode="FindAncestor" AncestorType="UserControl"/>
                                    </bind:BindingHelper.Binding>
                                </i:InvokeCommandAction>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </DataTemplate>
            </esri:Legend.LayerTemplate>

Johnny


I'd like to alter my legend control so that the user can right click on a map service or a layer within a map service, get a context menu with a "What's this?" option which will return the Service or Layer description from the map service (via webclient.downloadstringasynch()...).  I've done similar things with TreeView controls in the past but they have an actual RightMouseButtonDown event - LayerItemViewModels do not as far as I can see.  Is it possible to wire a mouse event to the Legend's controls?  If so, can I get a hint in the right direction?  Thanks,

Terry
0 Kudos
TerryGiles
Frequent Contributor
Thank you Johnny, looks exactly like what I need.  Will give it a try.

Terry
0 Kudos