Select to view content in your preferred language

Maptip binding issues (creating maptips on graphics layers programmatically)

1890
1
12-09-2010 07:23 AM
AlexZlotin
Emerging Contributor
I am programmatically adding graphics layers to a map and assigning maptips to these layers. I am running into a problem with binding, as the field values do not get displayed in the maptips.

Thanks in advance for any insights.
Alex

private void DisplayLayerMaptips(FeatureSet featureSet, FeatureLayerConfig featureLayerConfig)
{
    //Locate graphics layer by name
    string maptipGraphicsLayerId = "Maptip_" + featureLayerConfig.Id.ToString();
    GraphicsLayer graphicsLayerMaptip = (GraphicsLayer)MainMap.Layers[maptipGraphicsLayerId];

      //If graphics layer is not present in the map, create it and assign maptip 
      if (graphicsLayerMaptip == null)
      {
        StackPanel maptipPanel = new StackPanel() { Orientation = Orientation.Vertical };

         //Add field names and values (as bindings) to maptip
        foreach (FieldConfig fieldConfig in featureLayerConfig.MaptipFields)
        {
            StackPanel fieldPanel = new StackPanel() { Orientation = Orientation.Horizontal };
            TextBlock fieldNameText = new TextBlock() { Text = featureSet.FieldAliases[fieldConfig.Name]};
            TextBlock fieldValueText = new TextBlock();
            Binding binding = new Binding(fieldConfig.Name);
            fieldValueText.SetBinding(TextBlock.TextProperty, binding);  

            fieldPanel.Children.Add(fieldNameText);
            fieldPanel.Children.Add(fieldValueText);

            maptipPanel.Children.Add(fieldPanel);
          }

        graphicsLayerMaptip = new GraphicsLayer() { ID = maptipGraphicsLayerId };
        graphicsLayerMaptip.MapTip = maptipPanel; 
        MainMap.Layers.Add(graphicsLayerMaptip);
      }
      else
        graphicsLayerMaptip.ClearGraphics();

      //Add features to the graphics layer 
      foreach (Graphic feature in featureSet.Features)
      {
        feature.Symbol = CreateSymbolForMaptip(feature.Geometry);  
        graphicsLayerMaptip.Graphics.Add(feature);
      }
}
0 Kudos
1 Reply
AlexZlotin
Emerging Contributor
Found the answer myself... The names of the fields to be bound need to be surrounded by square brackets.

Binding binding = new Binding("[" + fieldConfig.Name + "]");
fieldValueText.SetBinding(TextBlock.TextProperty, binding);
0 Kudos