Please give me a sample of adding a custom tooltip to the XamWebMap MapLayer that would be attached to an .shp file and would have a TextBlock bound to a DataMapping item.
Hi flowerdj,
By default you could use Caption inside DataMapping:
<ig:MapLayer
Name="World" Brushes="#4C2C42C0 #4C218B93 #4CDC1C1C #4C3D7835 #4C701B51"
FillMode="Choropleth" WorldRect="{Binding ElementName=MainWindow, Path=WorldRect}"
>
<ig:MapLayer.Reader>
<ig:ShapeFileReader Uri="ShapeFiles\Cntry00\Cntry00"
DataMapping="Name=CNTRY_NAME; Value=POP_CNTRY; Caption=CNTRY_NAME; ToolTip=CNTRY_NAME" />
</ig:MapLayer.Reader>
<ig:MapLayer.ValueScale>
<ig:LinearScale IsAutoRange="True"/>
</ig:MapLayer.ValueScale>
</ig:MapLayer>
If you want a custom tooltip you need to create a DataTemplate inside ValueTemplate and attach a ToolTip to some of the elements in your DataTaplete.Here is an appropriate sample:
DataMapping="Name=CNTRY_NAME; Value=POP_CNTRY; Caption=CNTRY_NAME" />
<ig:MapLayer.ValueTemplate>
<DataTemplate>
<Border CornerRadius="4" BorderBrush="#00666666" BorderThickness="2" Background="#00cccccc" Padding="8">
<StackPanel>
<TextBlock FontSize="10" FontWeight="Bold" Text="{Binding Path=Name, StringFormat='Name: {0}'}" />
<ToolTipService.ToolTip>
<TextBlock FontSize="10" FontWeight="Bold" Text="{Binding Path=Value, StringFormat='Population: {0}'}" />
</StackPanel>
</Border>
</ToolTipService.ToolTip>
</DataTemplate>
</ig:MapLayer.ValueTemplate>
Hope this can help :-)
Cheers!
Mihail
This works for a tooltip for the TextBlock within the DataTemplate however, I was hoping to have a tooltip available for the whole element so that if I hovered over any part of it I would see the tooltip. Is there a way to do that?
Which solution are you talking about? Mine or Mihail's? If you use the solution I proposed then the tooltip should show up no matter where you hover on the element, or do you mean something else?
-Graham
I was referring to yours (Grahan Murray). When I hover over the map element, the only time that I get a tooltip is when I am on the TextBlock. If I remove the first TextBlock, I get nothing.
HI,
I am going to create a case for this issue and will reply to you via our CHS System.
Sincerely,
Matt Developer Support Engineer
Absolutely Great!! I love Graham's solution. I have made it work for both the Districts and the School!
Thanks much!!!
Your sample code is using the Mihail's solution and the result should be something like:
And if the mouse pointer is moved away from the TextBlock the tooltip disappears. If you apply the Graham's solution the result would be:
I have only changed the ShapeFileREaders's DataMapping to set MapElements' Caption, e.g.: DataMapping="Name, Caption=STATE_NAME"
You can move the mouse anywhere in the boundaries of the mapElement and the tooltip will be visible.
I would have attached my shape file to this but the file attach that you have is limited to 200kB. You can pick up the schooldistrict shape file for Oregon from the Census (Tiger) site for shape files.
<
="HeatMap.MainPage"
="clr-namespace:Infragistics.Silverlight.Map;assembly=Infragistics.Silverlight.DataVisualization.Map.v9.2"
="LayoutRoot">
="10,20,0,0">
="SchoolDistricts">
="Name=NAME;District_ID=INST_ID;County_Name=CNTY"/>
="True"/>
="8">
="Vertical">
=Name}"/>
</