Format InfoWindow Contents?

3163
10
12-16-2010 12:42 PM
AndrewHargreaves
Occasional Contributor II
Hi All,
I have a map of office locations that are currently 'Clustered' by the number of people in each, with a maximum flare count of 10. If < 10 people per office the point flares out and I use a maptip to show the name, email, phone number etc.

I'm using an Info window instead of maptips on those points where I have > 10 people. For example, I may have over 30 Names, Emails and Phone Numbers at one point. I can easily interrogate the attributes of the selected graphic/point to get all the info I need and drop it into a string for display in the infowindow.
 
However, how do I go about formatting it before displaying it? I'd like to add it into some kind of template or grid to organise it.

Thanks
0 Kudos
10 Replies
DominiqueBroux
Esri Frequent Contributor
You can template the InfoWindow with an ItemsControl (such as a ListBox) and set the Content to an enumeration of graphics.

if (selected.Count() > 10)
{
 
    MyInfoWindow.Anchor = e.MapPoint;
    MyInfoWindow.IsOpen = true;
    //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
    MyInfoWindow.Content = selected;
  return;
}
And XAML:
<esri:InfoWindow x:Name="MyInfoWindow"
                   Padding="2"
                   CornerRadius="20" 
                   Background="LightSalmon"
                   Map="{Binding ElementName=MyMap}" 
                   MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp" >
<esri:InfoWindow.ContentTemplate>
<DataTemplate>
 <ListBox ItemsSource="{Binding}" MaxHeight="150">
  <ListBox.ItemTemplate>
   <DataTemplate>
    <StackPanel Orientation="Horizontal">
     <TextBlock Text="{Binding Attributes[Name]}" Foreground="Black" FontSize="12" />
     <TextBlock Text="{Binding Attributes[EMail]}" Foreground="Black" FontSize="12" />
    </StackPanel>
   </DataTemplate>
 </ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</esri:InfoWindow.ContentTemplate>
</esri:InfoWindow>
0 Kudos
KevinSesock
New Contributor
I'm wanting to set up my InfoWindow like the Identify query grid (from this link: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify) and be able to customize further. We have overlapping layers that means that it would be easier for an end-user to be able to select a drop-down based on what's under the MapPoint. In other words, I would want to use the InfoWindow as a wrapper for this Identify grid primarily for the purposes of positioning the window and pointing to the map point that was clicked on.

Any thoughts?
0 Kudos
JenniferNery
Esri Regular Contributor
Sure. In that sample, you can put IdentifyComboBox in your InfoWindow template. This contains the layers that were underneath the mouse click. Look at where ShowFeatures() is called.
0 Kudos
KevinSesock
New Contributor
I guess I'm just somewhat confused since the example at this URL:

http://help.arcgis.com/en/webapi/silverlight/2.1/samples/start.htm#InfoWindowSimple

Is using a Feature Layer for the query. In addition, I can't reference the "IdentifyComboBox" via the x:Name component in the code-behind. It says it does not exist in the current context. I assume this is because the IdentifyComboBox (not to mention the datagrid as well) are in a DataTemplate, not in the the true xaml layout. Any thoughts?
0 Kudos
JenniferNery
Esri Regular Contributor
In your previous post, you mentioned you wanted to modify the following sample:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify.

IdentifyComboBox exists in this sample. The relevant code for ShowFeatures() is in the code-behind.

From my understanding, you want to add InfoWindow that contains what the IdentifyComboBox contain (layer name) and base on this selection, you want to display information on the Grid. If I understood you correctly, I think what you need to do then is first modify the Identify sample and then use InfoWindow sample as guideline on how to update its template and use in your application. Basically, learn both samples, tweak for your need and merge 🙂
0 Kudos
KevinSesock
New Contributor
No, I also want the grid inside the IdentifyComboBox. We'd like to have the information popup with the query info happen at the point where the user is viewing, not to the side or bottom of the screen. I've already managed to take my grid and my IdentifyComboBox and move them around the screen using e.MapPoint and settings the margins, but this is kludgey and suffers from some issues. Instead, I'd much rather have the IdentifyComboBox and the IdentifyResultsPanel be inside the InfoWindow.
0 Kudos
KevinSesock
New Contributor
Any thoughts on this? Would this be possible?
0 Kudos
JenniferNery
Esri Regular Contributor
It is possible. You just need to modify the DataTemplate of your InfoWindow. Or you can also create a UserControl that contains the IdentifyGrid and use it as your maptip. You may also need to update Binding statements and/or DataContext of your control.
0 Kudos
KevinSesock
New Contributor
But if I'm putting controls in the DataTemplate, can I refer to them via x:Name in code-behind? This is what doesn't seem to work for me.
0 Kudos