I'm trying to use a button with behavior in the MapLayerTemplate of an Esri Silverlight SDK 2.1 legend.

When I click the button and then drag on the map, the map pans instead of showing a selection rectangle.

The behavior code is pulled from this sample, while the legend is from this sample.

If I put the same xaml code within the layoutroot, it works as expected - I see a selection rectangle and the selection completes successfully.

<esri:Legend x:Name="MyLegend" Map="{Binding ElementName=MyMap}"  
            <StackPanel Orientation="Horizontal">
            <CheckBox Content="{Binding Label}"
                    IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                    IsEnabled="{Binding IsInScaleRange}">                                
                <Button Content="Select">
                        <i:EventTrigger EventName="Click">
                                Symbol="{StaticResource GraphicsLayerFillSymbol}"         
                                TargetName="MyMap" />
                <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
            <CheckBox Content="{Binding Label}"
            IsChecked="{Binding IsEnabled, Mode=TwoWay}"
            IsEnabled="{Binding IsInScaleRange}" >

Update: Following Seth's suggestion I tried wiring the trigger in the code-behind. I get the same results. The code behind approach fails for the button in the datatemplate, but works for the one on a stackpanel sibling to the map.

private void Assign_Behavior_Click(object sender, RoutedEventArgs e)
    var button = sender as Button;
    ESRI.ArcGIS.Client.Actions.SpatialQueryAction sqa = new ESRI.ArcGIS.Client.Actions.SpatialQueryAction();
    sqa.DrawMode = DrawMode.Rectangle;
    sqa.LayerID = "MyGraphicsLayer";
    sqa.Url = @"http://hq-gis-01/ArcGIS/rest/services/WaterInfrastructure2/MapServer/15";
    sqa.Symbol = LayoutRoot.Resources["GraphicsLayerFillSymbol"] as Symbol;
    sqa.TargetName = "MyMap";

    var et = new System.Windows.Interactivity.EventTrigger("Click");
    var triggerColl = System.Windows.Interactivity.Interaction.GetTriggers(button);

I'm beginning to think this is not an Esri issue - I can't find an example anywhere showing how to attach trigger actions from buttons in a datatemplate.

  • What happens when you click the button? Does it enter the Assign_Behavior_Click event and then do nothing? – Britt Wescott Dec 8 '10 at 21:03

I was able to replicate this issue, it may be a bug with ESRI's API. You can put a Click event in the Select button to hit the code-behind and then use this technique to call the action:


As Dominique states, it's probably not recommended to use Actions in the code-behind, however in this case, I don't see any alternative.

  • Thanks Seth. I've updated my question with your suggestion. – Kirk Kuykendall Dec 8 '10 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.