Select to view content in your preferred language

MapTips via Code-Behind

3174
4
09-01-2010 01:38 AM
AlexanderBlock
New Contributor
Hello,

is there any possibility to add MapTips to a GraphicsLayer via Code-Behind?

Code like the following ends with an ArgumentException when I hover over a MarkerSymbol;

var mapTip = (FrameworkElement)ESRIMap.Resources["ESRIMapTip"];
ObjectsGraphicsLayer.MapTip = mapTip;

For test purposes I use no binding in the MapTip XAML. It's just a plain border.

Any idea?

Regards,
Benjamin
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
MapTip can't be defined as resource (even in XAML).

But you can define it by code the same way than in XAML : ObjectsGraphicsLayer.MapTip = new Border() { ......
0 Kudos
dotMorten_esri
Esri Notable Contributor
I would create a custom usercontrol that contains everything you want in the maptip (including borders etc).
Then programmatically you simply set:
MyGraphicsLayer.MapTip = new MyMapTipUserControl();

You can still do all the binding stuff in this user control as you normally would when defining it straight in the Xaml.
0 Kudos
PaulHuppé
Deactivated User
Hi,

I would also like to define map tips from code-behind.  I need to setup map tips for several layers each with a different list of fields to display. As Morton says, maybe a custom user control would do to define the look, but how do I pass it the fields I want to show?

Paul
0 Kudos
dotMorten_esri
Esri Notable Contributor
In you custom control you can generate the fields based on the Keys.
if add a Dependency Property to the UserControl and do the binding to that ie <local:MyMapTipControl Data="{Binding} />. In the DependencyPropertyChanged event handler, in the grid you have that contains the fields clear its children and its row definitions , and do a simple foreach on the keys/values to generate some new matching textblocks:
ie
int i=0;
foreach(var key in Data.Keys)
{
    ContainerGrid.Rows.Add(new RowDefinition());
    TextBlock tb = new TextBlock() { Text = key };
    tb.SetValue(Grid.Column, i++);
    ContainerGrid.Children.Add(tb);
    TextBlock tb2 = new TextBlock() { Text = value };
    tb.SetValue(Grid.Column, i);
    tb.SetValue(Grid.Row, 1); 
    ContainerGrid.Children.Add(tb2);
}
0 Kudos