How to bind MapTip DataContext

335
1
02-27-2013 06:46 AM
Labels (1)
GregLutz
New Contributor II
I have a collection of Users which are bound to a GraphicsLayer using a PointDataSource. The graphics appear OK, but the MapTips do not bind to the User properties.

My User class looks like this:
public class User
{
    public User()
    {
        //empty
    }

    public User(double lon, double lat)
    {
        this.Latitude = lat;
        this.Longitude = lon;
    }

    public string FirstName { get; set; }
    public string LastName { get; set; }
    public double Longitude { get; set; }
    public double Latitude { get; set; }
}


My ViewModel also exposes a Users ObservableCollection which is bound to my PointDataSource.

<!-- data source -->
<esri:GraphicsLayer.GraphicsSource>
    <esri:PointDataSource 
        ItemsSource="{Binding Source={StaticResource usersViewModel}, Path=Users}"  
        XCoordinateBinding="{Binding Longitude}"
          YCoordinateBinding="{Binding Latitude}" >
    </esri:PointDataSource>
</esri:GraphicsLayer.GraphicsSource>


How can I bind my MapTip to display the FirstName and LastName properties from my user? Currently I have this below, however the DataContext on the Border is always null. I don't know how to bind this to the point which contains the User instance for each specific map tip.

<!-- tooltip -->
<esri:GraphicsLayer.MapTip>
    <Border Padding="4,2" Background="Black" DataContext="{Binding [DataContext]}">
        <StackPanel>
            <TextBlock Foreground="White" Loaded="TextBlock_Loaded">
                <Run Text="User: " />
                <Run Text="{Binding FirstName}" />
                <Run Text="{Binding LastName}" />
            </TextBlock>
        </StackPanel>
    </Border>
</esri:GraphicsLayer.MapTip>


Graphics display correctly for each User (Lat/Long is good) but the MapTips appear empty.

Thanks
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
If 'Firstname' and 'LastName' are attributes of your graphics, you should get your maptip working with code like:
<!-- tooltip -->
<esri:GraphicsLayer.MapTip>
    <Border Padding="4,2" Background="Black">
        <StackPanel>
            <TextBlock Foreground="White" Loaded="TextBlock_Loaded">
                <Run Text="User: " />
                <Run Text="{Binding [FirstName]}" />
                <Run Text="{Binding [LastName]}" />
            </TextBlock>
        </StackPanel>
    </Border>
</esri:GraphicsLayer.MapTip>
0 Kudos