Select to view content in your preferred language

MapTip binding to Graphic.Attributes path problem.

991
3
03-24-2011 12:25 PM
EduardLucic
Emerging Contributor
I was trying the following:

<esri:Map x:Name="m_internalControl" Background="White">
    <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
    <esri:GraphicsLayer ID="MyGraphics" >
        <esri:GraphicsLayer.MapTip>
            <Border BorderBrush="DarkGray" CornerRadius="13" BorderThickness="1" Margin="0,0,15,15">
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
                </Border.Effect>
                <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="5" BorderBrush="#77FF0000">
                    <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Name: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center"/>
                            <TextBlock Text="{Binding [GraphicData].Name}" HorizontalAlignment="Left" VerticalAlignment="Center" />
                        </StackPanel>
                    </StackPanel>
                </Border>
            </Border>
        </esri:GraphicsLayer.MapTip>
    </esri:GraphicsLayer>
</esri:Map>

...

internal class GraphicData : INotifyPropertyChanged
{
  private string _name = null;

  public string Name
  {
    get { return _name; }
    set
    {
      _name = value;
      if (PropertyChanged != null)
      {
        PropertyChanged(this, new PropertyChangedEventArgs("Name"));
      }
    }
  }

  public event PropertyChangedEventHandler PropertyChanged;
}

...

GraphicsLayer gLayer = m_internalControl.Layers["MyGraphics"] as GraphicsLayer;
Graphic g = new Graphic();
g.Symbol = this.Resources["RedMarkerSymbol"] as Symbol;
g.Geometry = new MapPoint(-140.9, 63.391);
g.Attributes["GraphicData"] = new GraphicData() { Name = "Graphic 1" };
gLayer.Graphics.Add(g);


With a WPF application, the MapTip appears as expected with "Name: Graphic 1". With Silverlight, the bound value is empty and the MapTip appears with "Name:". Is there a different notation needed for Silverlight? Is it a bug? I'm using API 2.1.

Thanks,
Ed
0 Kudos
3 Replies
EduardLucic
Emerging Contributor
By the way, I have the same issue with custom MarkerSymbol binding:

<esri:MarkerSymbol x:Key="CustomMarkerSymbol">
    <esri:MarkerSymbol.ControlTemplate>
        <ControlTemplate>
            <Grid>
                <TextBlock Text="{Binding Attributes[GraphicData].Name}" />
            </Grid>
        </ControlTemplate>
    </esri:MarkerSymbol.ControlTemplate>
</esri:MarkerSymbol>


Works in WPF, but not in Silverlight.

Ed
0 Kudos
JenniferNery
Esri Regular Contributor
I tried your code in Silverlight and WPF. You are right WPF allows you to access internal class GraphicData. Your syntax is perfectly fine but Silverlight cannot access this internal class. If you make GraphicData class public, it should work.

http://connect.microsoft.com/VisualStudio/feedback/details/526229/in-silverlight-4-binding-to-an-int...
0 Kudos
EduardLucic
Emerging Contributor
Thanks Jennifer! Worked like a charm 😉

Ed
0 Kudos