Select to view content in your preferred language

Binding search result from FindTask to ListBox using DataTemplate SL4

5082
13
03-07-2011 10:06 AM
MariaFernandez
Deactivated User
Hi, I am trying to bind the FindTask result to a listbox with ItemTemplate defined as a StaticResource (DataTemplate).
I got error:
Unable to cast object of type 'System.Windows.Data.Binding' to type 'System.Collections.IEnumerable'

Thanks!!
0 Kudos
13 Replies
MariaFernandez
Deactivated User
The FindResult object contains a feature object with all its attributes. So you can extend your FeatureItem to store other attributes:
     .OtherAttribute = .elem.Feature.Attributes["AttributeName"]

or even to store the whole Feature:
.Feature= .elem.Feature


That will be easier if you store the Feature in your FeatureItem. So (as in the sample) from the SelectedItem, you can retrieve the Feature and show it in a graphics layer.


I already added the Feature to the FeatureItem class. Now I need to add a MouseEnter/Leave event to the Listbox that has the result, but this listbox is defined inside the DataTemplate. How and where I could add those event?
THANKS  !!!!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I also need the legend dymbol for the layer. The image I have in the feature class is to store the legend symbol for the layer. How we can access that information?

If you have included a legend control in your application, you can use it to get the swatches of the sublayers (look at this thread http://forums.arcgis.com/threads/23147-populating-sublayers-on-a-listbox-along-with-the-symbols) else you could call QueryLegendInfos of the service by yourself.



Now I need to add a MouseEnter/Leave event to the Listbox that has the result, but this listbox is defined inside the DataTemplate. How and where I could add those event?


Why not just hook up your handler in XAML?
 
<DataTemplate x:Key="FeatureItemDataTemplate">
<Grid MouseEnter="Grid_MouseEnter">
........
0 Kudos
MariaFernandez
Deactivated User
If you have included a legend control in your application, you can use it to get the swatches of the sublayers (look at this thread http://forums.arcgis.com/threads/23147-populating-sublayers-on-a-listbox-along-with-the-symbols) else you could call QueryLegendInfos of the service by yourself.




Why not just hook up your handler in XAML?
 
<DataTemplate x:Key="FeatureItemDataTemplate">
<Grid MouseEnter="Grid_MouseEnter">
........


I have defined the DataTemplate as a Resource. When I add the event declaration there I got errors, where I can defined it in the App.xaml?
Or you think is better to move the whole dataTemplate back to the page and have it locally?
Or declare the event in the class and bind in the dataTemplate?

Thanks a lot for your help!!!
0 Kudos
MariaFernandez
Deactivated User
Thanks a lot!!!!!!!
It is working now!!
I had to move the DataTemplate to inside the control to be able to add the SelectionChange event to the inner ListBox control. Later I will isolated this example to try to put back the DataTemplate in a asset (as a resource) as before (what I am missing is be able to call or bind an event (and I need to know where we have to define it) inside a DataTemplate defined as resource).
For now the list is working.

Once again THANK YOU!!!!!!!!


<ListBox x:Name="SearchListBox" Background="White"
                                             ItemsSource="{Binding}"
                                         
                                             VerticalAlignment="Top"    >
                                    <ListBox.ItemsPanel>
                                        <ItemsPanelTemplate  >
                                            <StackPanel Orientation="Horizontal"  />
                                        </ItemsPanelTemplate>
                                    </ListBox.ItemsPanel>
                                    <ListBox.ItemTemplate >
                                        <DataTemplate >
                                            <Grid Width="auto">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="85"/>
                                                    <RowDefinition/>
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>

                                                </Grid.ColumnDefinitions>
                                                <Border BorderThickness="3"  Grid.RowSpan="2" Grid.Column="0" >
                                                    <Image Source="{Binding SymbolLayer}" Stretch="Fill"   />
                                                </Border>

                                                <dataInput:Label Content="{Binding FeatureLayerName}" Grid.Row="0" Grid.Column="1" />
                                                <dataInput:Label Content="{Binding FeatureLayerItemCount}" Grid.Row="1" Grid.Column="1"/>


                                                <ListBox x:Name="LBFeatureItems"  Padding="2" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
                                                     ItemsSource ="{Binding Path=FeatureItems}"
                                                     SelectionChanged="LBFeatureItems_SelectionChanged"   
                                                     >
                                                    <ListBox.ItemTemplate >
                                                        <DataTemplate >
                                                            <Grid   >
                                                                <Grid.ColumnDefinitions>
                                                                    <ColumnDefinition Width="50"/>
                                                                    <ColumnDefinition Width="100"/>
                                                                </Grid.ColumnDefinitions>
                                                                <Grid.RowDefinitions >
                                                                    <RowDefinition ></RowDefinition>
                                                                    <RowDefinition ></RowDefinition>
                                                                </Grid.RowDefinitions>
                                                                <sdk:Label x:Name="labelName" Content="Name:" Grid.Column="0" Grid.Row="0"/>
                                                                <dataInput:Label Content="{Binding Path=Name}" Grid.Row="0" Grid.Column="1"/>

                                                                <sdk:Label x:Name="labelOwner" Content="Owner:" Grid.Column="0" Grid.Row="1"/>
                                                                <dataInput:Label Content="{Binding Path=Owner}" Grid.Row="1" Grid.Column="1"/>

                                                            </Grid>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                   
                                                </ListBox>


                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                   
                                </ListBox>


THANKS!!!
0 Kudos