Adding map tips in code behind.

552
1
10-12-2012 04:35 AM
SanajyJadhav
Occasional Contributor II
Hello,

I know that this is issue has been discussed many times on this forums, but still I am stuck.

I have 2 feature layers on which I want to display map tips when mouse is hovered.I want to show 2 field values in map tips. I wrote following code to do this that shows hard-coded value.

 void FeatureLayer_Initialized(object sender, EventArgs e)
        {
            FeatureLayer ptFeatLayer = sender as FeatureLayer;

            Grid mainGrid = new Grid();
            mainGrid.Background = new SolidColorBrush(Colors.Yellow);  

            TextBlock txtBlock = new TextBlock();
            Binding b = new Binding();
            b.Source = "Some Attribute value";
            txtBlock .SetBinding(TextBlock.TextProperty, b); 
            mainGrid.Children.Add(txtBlock );
           
            ptFeatLayer.MapTip = mainGrid;
        }


The lines which are shown bold in above code are critical for me. I am simply not being able to translate xaml binding code to code behind.

So,  can anybody please show me how to bind my textblock to the value of the mouse hovered feature in code behind.

Appreciate any help. Thanks.
0 Kudos
1 Reply
HyrumErnstrom
New Contributor III
Try it without setting the b.Source. This will then use the DataContext to pull the values. You will still need to set the path in the Constructor like new Binding("Attributes.[FIELDNAME]");
0 Kudos