Select to view content in your preferred language

Binding to a maptip value

783
2
03-21-2014 07:01 AM
gabrielvazquez
Deactivated User
I'm attempting to bind a string in behind code to a textblock value in a maptip. Not sure if there was a specific way to do this, but I cant seem to get it to work. I'm attempting to run a spatial query using geometry from a chosen graphic in a feature layer similar to this thread:  http://forums.arcgis.com/threads/48259-Select-FeatureLayer-graphic-based-on-DataGrid-click

The feature layer in the XAML has a maptip textblock which is binding to the feature layer "Name" field. I also placed a button in the maptip, once the user clicks on the button, it should run a query using the textblock.text to find the correct graphic, then assign that graphic.geometry to an additional spatial search. However, I cant seem to grab the maptip.textblock value from behind the code. When I attempt to grab the textblock.text in Code it comes up null. Not if this is because i'm simply binding the text value to the featurelayer on the fly, or why.

Below is some of my code, if anyone has any recommendations please let me know. 

Here is the XAML for the featurelayer, i left out some of the unimportant code
<esri:FeatureLayer ID:"EllipseLayer" Url"http//...." OutFields="*">
<esri:Featurelayer.MapTip>
<TextBlock x:Name="EllipseLayerName" Text="{Binding [Name]}" />
<Button x:Name="GetEllipseNameBtn" Click="GetEllipseNameBtn_Click"/>
</esri:Featurelayer.MapTip>
</esri:FeatureLayer />


Here is the C# Code for when the Button is clicked
FeatureLayer fl = Map.Layers["EllipseLayer"] as FeatureLayer;

Graphic gl = fl.Graphics.Where(g => g.Attributes["Name"].ToString() == EllipseLayerName.Text).First();


Not sure if I need to reference the EllipseLayerName in the maptip differently but it continues to come up null. When I create a temporary string and use that string with a defined value the query works fine.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
The maptip is not in the same namespace as the main window so you can't use the element name this way.

Instead use the datacontext which is set with the dictionary of attributes.
Something like:
var button = sender as Button;
var attributes = button.DataContext as IDictionary<string, object>;
var currentName = attributes["Name"].ToString();
....
0 Kudos
gabrielvazquez
Deactivated User
DOH! That worked! Thank you, I'm actually doing something very similar in another portion of my project, totally forgot.

Thank you again Dominique!
0 Kudos