Select to view content in your preferred language

Commands not working for making selections on Feature Layers

938
5
05-13-2010 12:51 PM
MikeKaufman
Emerging Contributor
I am building a desktop WPF app using v2.0 of the ESRI Silverlight/WPF API.  In my attempt to learn both WPF and the ESRI control I am failing to successfully get the selection tools working as seen in the Feature Layer Selection Sample http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerSelection.  I copy the XAML from the Sample into my project and when I run it none of the buttons are enabled.   The select command is either not getting called or it is just plan out not working.  Is anyone else having this issue?  What can I do to debug the issue or better yet get it things working?  Thanks in advance to anyone how helps!
0 Kudos
5 Replies
MikeKaufman
Emerging Contributor
So I have managed to find a work around for now.  In order for the editor commands to start working correctly I had to move the Editor declaration into my code behind and instantiate it as a global level variable.  I did remove the Editor from the Grid.Resources in the XAML.  Here is my code behind:

Public Class MapFeatureSelect
    Private _vm As New LayerViewModel
    Public MyEditor As New ESRI.ArcGIS.Client.Editor

    Sub New()
        DataContext = _vm
        Resources.Add("MyEditor", MyEditor)


        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        EditorToolStrip.DataContext = MyEditor
    End Sub

    Private Sub MyMap_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyMap.Loaded
        Dim lst As New List(Of String)
        lst.Add("SelectionLayer")
        With MyEditor
            .Map = MyMap
            .SelectionMode = ESRI.ArcGIS.Client.DrawMode.Rectangle
            .LayerIDs = lst
        End With
    End Sub
End Class


This is an attempt to do MVVM with the WPF map control.  I would much rather do this in XAML so if any has any advice please post!  Thanks
0 Kudos
dotMorten_esri
Esri Notable Contributor
If you have the editor defined in the resources, note that WPF (as opposed to Silverlight) doesn't support ElementBinding, so you will have to set the Map property in codebehind.
0 Kudos
MikeKaufman
Emerging Contributor
I am confused by your response.

If you have the editor defined in the resources, note that WPF (as opposed to Silverlight) doesn't support ElementBinding, so you will have to set the Map property in codebehind.


I believe that WPF does have element binding. I am able to bind to elements in WPF just fine, even when implementing ESRI Silver Light sample code in WPF.
 <ListBox x:Name="MyList" ItemsSource="{Binding ElementName=MyMap, Path=Layers}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <!--Layer visibility checkbox-->
                            <CheckBox IsChecked="{Binding Visible, Mode=TwoWay}" />
                            <!--Opacity slider-->
                            <Slider Margin="-5,0,0,0" Minimum="0" Maximum="1" Width="30" 
                                Value="{Binding Opacity, Mode=TwoWay}" Height="18" />
                            <!--Layer name-->
                            <TextBlock Text="{Binding ID, Mode=OneWay}" Margin="5,0,0,0" > 
                            <!-- Tooltip on hover-->
                                <ToolTipService.ToolTip>
                                    <StackPanel MaxWidth="400">
                                        <TextBlock FontWeight="Bold" Text="{Binding CopyrightText}" TextWrapping="Wrap" />
                                        <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
                                    </StackPanel>
                                </ToolTipService.ToolTip>
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>


Also I tried creating a silver light app by coping the exact XAML from the interactive SDK sample and the commands still do not work, the buttons do the activate on the EditorToolsStrip. I donâ??t think this a WPF issue; I think there might be a bug in v2.0
0 Kudos
dotMorten_esri
Esri Notable Contributor
Let me emphazise what I wrote earlier:
"If you have the editor defined in the resources WPF doesn't support ElementBinding"
ElementBinding works great from controls in the UI tree, like your listbox above, but it is not supported in WPF from objects inside the resources property.
0 Kudos
MikeKaufman
Emerging Contributor
Thanks for the clarification!
0 Kudos