Select to view content in your preferred language

Locator results issue after upgrade(s)

621
4
06-03-2010 11:41 AM
LanceCrumbliss
Frequent Contributor
hi all,

after the upgrade to the v2 beta or VS2010 - i'm not sure which one is causing the issue - a textblock in XAML as such

  <Popup x:Name="locationResultsPopUp" IsOpen="True" HorizontalAlignment="Left" VerticalAlignment="Top">
   <ListBox x:Name="locationResults" Background="White"  SizeChanged="locationResults_SizeChanged"
       SelectionChanged="locationResults_SelectionChanged" 
        Visibility="Collapsed"
       LostFocus="locationResults_LostFocus">
    <ListBox.ItemTemplate>
     <DataTemplate>
      <TextBlock Foreground="#002969" FontSize="9" Text="{Binding [Descr]}"/>
     </DataTemplate>
    </ListBox.ItemTemplate>
   </ListBox>
  </Popup>


no longer will display the value of the Descr key of an AddressCandidate. the list box will contain the correct number of items...i can tell by the height of it. however, what should be the Descr key of the AddressCandidates is not displayed on each line of the listbox. What has changed?
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
Difficult to answer without seeing your code.

I guess the ItemsSource is initialized by code. It should be initialized to a collection of Dictionary.

From your description it looks like it's well initialized to a collection (because you see the correct number of item). 
But either the item is not a dictionary or the key "Descr" is not existing in the dictionary.
0 Kudos
LanceCrumbliss
Frequent Contributor
Difficult to answer without seeing your code.

I guess the ItemsSource is initialized by code. It should be initialized to a collection of Dictionary.

From your description it looks like it's well initialized to a collection (because you see the correct number of item). 
But either the item is not a dictionary or the key "Descr" is not existing in the dictionary.


This code and the XAML above worked just fine before the upgrade.

 Private Sub LocatorTask_AddressToLocationsCompleted(ByVal sender As Object, ByVal args As AddressToLocationsEventArgs)

  Dim FullList As List(Of AddressCandidate) = args.Results
  Dim returnedCandidates As New List(Of AddressCandidate)

  For Each AddressCandidate As AddressCandidate In FullList
   If (AddressCandidate.Attributes("State") = "Louisiana" Or AddressCandidate.Attributes("State") = "Texas") Then
    returnedCandidates.Add(AddressCandidate)
   End If
  Next


  If returnedCandidates.Count = 1 Then
   Dim best As AddressCandidate = returnedCandidates(0)

   Dim env As New Envelope() With {.XMin = Double.Parse(best.Attributes("West_Lon").ToString(), CultureInfo.InvariantCulture), _
     .YMin = Double.Parse(best.Attributes("South_Lat").ToString(), CultureInfo.InvariantCulture), _
     .XMax = Double.Parse(best.Attributes("East_Lon").ToString(), CultureInfo.InvariantCulture), _
     .YMax = Double.Parse(best.Attributes("North_Lat").ToString(), CultureInfo.InvariantCulture)}

   Dim MyDescr As String = best.Attributes("Descr").ToString.Replace(", United States", "")
   locationTextBox.Text = MyDescr
   env = env.GeographicEnvToWebMercatorEnv 'Extension Method
   Map.ZoomTo(env)
  ElseIf returnedCandidates.Count > 1 Then
   locationResults.Visibility = Visibility.Visible
   locationResults.ItemsSource = returnedCandidates
  Else
   locationTextBox.Text = "Location Not Found (LA/TX)"
  End If
 End Sub
0 Kudos
DominiqueBroux
Esri Frequent Contributor
{Binding [Descr]} should be replaced by  {Binding Attributes[Descr]} (your item is not a dictionary by itself)
0 Kudos
LanceCrumbliss
Frequent Contributor
that's the ticket.  I couldn't find that change in any documentation so thanks a lot, dominique!
0 Kudos