question regarding programmatically created graphicslayer & maptips

3821
16
10-19-2010 08:56 AM
MikeDavis
New Contributor
I'm using the beta 2.1 API and taking an RSS feed that has lat/long coordinates and adding it to a GraphicsLayer that I've programmatically created - I've added some of the attributes to each of the graphics as such and added them to a graphicslayer called pGraphicsLayer:

          
graphic.Attributes.Add("Title", item.Title.Text)
graphic.Attributes.Add("Summary", item.Summary.Text)
graphic.Attributes.Add("PublishDate", item.PublishDate)
                    If item.Links.Count > 0 Then
                        graphic.Attributes.Add("Link", item.Links(0).Uri)
                    End If
graphic.Attributes.Add("FeedItem", item)
graphic.Attributes.Add("Id", item.Id)



I've put a UserControl on my XAML page as such:

        <UserControl x:Name="hmTooltip" HorizontalAlignment="Left" Margin="132,141,0,289" Width="140">
<TextBlock Text="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=FeedItem, Mode=OneWay}" 
HorizontalAlignment="Left" VerticalAlignment="Top"  TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Height="30" Width="190" FontSize="10" Foreground="Black" Margin="2,0,0,0" />
 </UserControl>


But for the life of me I can't figure out how to get the MapTips to work on the pGraphicsLayer object that I programmatically created (the points show up, etc but nothing on hover - it essentially crashes).  I've tried setting the pGraphicsLayer.MapTip = hmTooltip (my user control)

Am I going about this the correct way?  when I hover over i get the following message:

"Message: Unhandled Error in Silverlight 2 Application Value does not fall within the expected range."

Meanwhile I'm using a Silverlight 4 environment so not sure why that's giving me a Silverlight 2 error?
0 Kudos
16 Replies
DominiqueBroux
Esri Frequent Contributor
You don't need any binding,nor DP, nor datacontext initialization in your code.
Try this simple version:
 
public partial class MyMapTip : UserControl
    {
        public MyMapTip()
        {
            InitializeComponent();
        }
}


and call it like this: reportLayer.MapTip = new MyMapTip();

This should work : the binding is done in your XAML code and the initialization of the datacontext is done by the framework when the maptip opens up (the datacontext is set to the 'Attributes' property of the current graphic).
0 Kudos
stefanschlaefli
New Contributor III
Ok, but when I try to make the Tool generic I need to change the binding from outside. That's why I created this dependency property, which sets the binding instead of the default field called "VALUE" to another featurelayer field. How would you do that?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Ahhh, yes, I think I eventually got it 🙂

Try this:
 
public partial class MyMapTip : UserControl
{
  public MyMapTip()
  {
    InitializeComponent();
  }
  public static readonly DependencyProperty TipTextProperty = DependencyProperty.Register("TipText", typeof(String),   typeof(MyMapTip), new PropertyMetadata(TipText_PropertyChangedCallback));
  public string TipText
  {
    get { return (string)GetValue(TipTextProperty); }
    set { SetValue(TipTextProperty, value); }
  }
  private static void TipText_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  {
    MyMapTip myMapTip = d as MyMapTip;
    myMapTip.tb.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding((string)e.NewValue));
  }
}
0 Kudos
stefanschlaefli
New Contributor III
This works great 🙂
Merci Dominique
0 Kudos
DarkoRadiceski
New Contributor II
Hi there,

I was wondering if any of those examples for programatically loading an geoRss feed and perhaps using a custom user control available? I am currently stuck loading a geoRss feed and i would like to show an image that is part of the feed together with a custom graphic.

Any advice on programatic reading of the georss.
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos
JamilNawaz
New Contributor II
Hi,

I read the post, and trying to following that. I have created a data template.
[HTML]<DataTemplate x:Key="maptip">
<Border esri:GraphicsLayer.MapTipHideDelay="0:0:0.5">
  <StackPanel Orientation="Horizontal">
   <TextBlock VerticalAlignment="Center"
              FontSize="10"
              FontWeight="Bold"
              Foreground="Black"
              Text="Nombre: " />
   <TextBlock HorizontalAlignment="Left"
              VerticalAlignment="Center"
              FontSize="10"
              Foreground="Black"
              Text="{Binding [NOMBRE]}" />
  </StackPanel>
</Border>
</DataTemplate>[/HTML]

Then using, the code to define the map tip and binding.
gl.MapTip = new ContentControl() { ContentTemplate = (DataTemplate)Application.Current.Resources["maptip"] };
gl.MapTip.SetBinding(ContentControl.ContentProperty, new Binding());


But data does not appear. How can I display the attributes data? I might need to define binding in different way.

Regards,
JAMIL
0 Kudos