Select to view content in your preferred language

Add Hyperlink Control into the MapTip programatically

1021
8
01-10-2012 10:17 AM
AndresC
Emerging Contributor
Hi,
I need to add a HyperlinkButton into a mapTip programtically. I have a collection of Graphics loaded by code in the GraphicLayer, and have the MaptTip defined into the Layer. I can set attrbitues and bind but can not add a HyperlinkButton into the StackPanel "MapTipSPImages" because it is null at run time (seems it is not loaded yet or something). How I can access to this stack panel so can add controls?
Thanks.

The XAML:
<esri:GraphicsLayer ID="Landmarks">
    <esri:GraphicsLayer.MapTip>
     <Border esri:GraphicsLayer.MapTipHideDelay="00:00:02" BorderBrush="DarkGray" CornerRadius="13" BorderThickness="1" Margin="0,0,15,15" Loaded="MapTipLoaded">
      <Border.Effect>
       <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
      </Border.Effect>
      <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="4" BorderBrush="#77FF0000" Name="MapTipBorder">
       <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10">
        <StackPanel Orientation="Horizontal">
         <TextBlock Text="{Binding Path=[Event]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
        </StackPanel>
        <StackPanel Orientation="Horizontal">
         <TextBlock Text="User: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center"/>
         <TextBlock Text="{Binding Path=[User]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
        </StackPanel>
        <StackPanel Orientation="Horizontal">
         <TextBlock Text="Date: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center" />
         <TextBlock Text="{Binding Path=[Date]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
        </StackPanel>
        <StackPanel Orientation="Horizontal" Name="MapTipSPImages" >
</StackPanel>
       </StackPanel>
      </Border>
     </Border>
     </esri:GraphicsLayer.MapTip>
   </esri:GraphicsLayer>
0 Kudos
8 Replies
JMcNeil
Deactivated User
elcapitanAndres,

This will work.  It works for me but the thing is with a maptip is once you move the mouse away from the graphic and towards the hyperlink the maptip is gone....so I can never click on the hyperlink but I tested this in a simple stagnate grid and it works.  It also shows up in my maptips.


XML


 <StackPanel>

<TextBlock Name="HyperlinkString" Visibility="Collapsed" Text="{Binding [HyperLinkIDField]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                                <HyperlinkButton TargetName="_blank" Content="Click Me I'm a HyperLink" HorizontalAlignment="Center" Foreground="RED" NavigateUri="{Binding Text, ElementName=HyperLinkString, Mode=OneWay}"/>

                                            </StackPanel>





Jay
0 Kudos
JasonCleaver
Frequent Contributor
If you want the maptip to display for a short second, add the following: esri:GraphicsLayer.MapTipHideDelay="0:0:0.5"
0 Kudos
DominiqueBroux
Esri Frequent Contributor
but the thing is with a maptip is once you move the mouse away from the graphic and towards the hyperlink the maptip is gone....so I can never click on the hyperlink


By setting a MapTipHideDelay, you should have enough time to move the mouse from the graphic towards the maptip. Once the mouve is over the maptip, this one should not disappear.
0 Kudos
AndresC
Emerging Contributor
elcapitanAndres,

This will work.  It works for me but the thing is with a maptip is once you move the mouse away from the graphic and towards the hyperlink the maptip is gone....so I can never click on the hyperlink but I tested this in a simple stagnate grid and it works.  It also shows up in my maptips.


XML


 <StackPanel>

<TextBlock Name="HyperlinkString" Visibility="Collapsed" Text="{Binding [HyperLinkIDField]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                                <HyperlinkButton TargetName="_blank" Content="Click Me I'm a HyperLink" HorizontalAlignment="Center" Foreground="RED" NavigateUri="{Binding Text, ElementName=HyperLinkString, Mode=OneWay}"/>

                                            </StackPanel>





Jay


Thanks esrijay for the reply, but i don't see how to add a control into a maptip programatically (by code, I'm using C#), it is for the XAML, or I'm wrong?
0 Kudos
JMcNeil
Deactivated User
elcapitanAndres,

My code is XML not C#...Sorry for the confusion, I guess i'm lost on what you are trying to do. Originally you posted XML so I thought thats where you were working and wanted to stay. Why do it in C# when you can handle this in XML. You just want to create a hyperlink and when this link is clicked it takes the enduser to a website or image that is stored on your server? I'm binding to a fabricated field named "HyperLinkIDField" if you have a field with your link data just place that field there. I inserted my code into yours, it assumes that you have a field in your layer that has the link with the address (HyperLinkIDField) and then just binds that. Your code in RED - Mine in BLUE:



<esri:GraphicsLayer ID="Landmarks">
    <esri:GraphicsLayer.MapTip>
     <Border esri:GraphicsLayer.MapTipHideDelay="00:00:02" BorderBrush="DarkGray" CornerRadius="13" BorderThickness="1" Margin="0,0,15,15" Loaded="MapTipLoaded">
      <Border.Effect>
       <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
      </Border.Effect>
      <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="4" BorderBrush="#77FF0000" Name="MapTipBorder">
       <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10">
        <StackPanel Orientation="Horizontal">
         <TextBlock Text="{Binding Path=[Event]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
        </StackPanel>
        <StackPanel Orientation="Horizontal">
         <TextBlock Text="User: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center"/>
         <TextBlock Text="{Binding Path=[User]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
        </StackPanel>
        <StackPanel Orientation="Horizontal">
         <TextBlock Text="Date: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center" />
         <TextBlock Text="{Binding Path=[Date]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
        </StackPanel>


        <StackPanel Orientation="Horizontal" Name="MapTipSPImages" >


<TextBlock Name="HyperlinkString" Visibility="Collapsed" Text="{Binding [HyperLinkIDField]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                                <HyperlinkButton TargetName="_blank" Content="Click Me I'm a HyperLink" HorizontalAlignment="Center" Foreground="RED" NavigateUri="{Binding Text, ElementName=HyperLinkString, Mode=OneWay}"/>

</StackPanel>
      </StackPanel>
      </Border>
     </Border>
     </esri:GraphicsLayer.MapTip>
   </esri:GraphicsLayer>



Once again sorry for the confusion I guess I'm a little lost; if this is not what you want can you post your needs again and I'll take a look.

Thanks
J
0 Kudos
DaveTimmins
Deactivated User
Hi,

have you checked this thread http://forums.arcgis.com/threads/22728-Identify-Tool-multiple-layers-Hyperlinks it may aid in your issue.
0 Kudos
AndresC
Emerging Contributor
Thanks for the reply.
esrijay, sorry for the confusion, I posted the XAML code just to show how is the structure of my mapTip.
I need to add Hyperlinkbutton dinamically (C#), because I don't know how many links I have to show (could be none), because they are loaded through javascript.
The HyperlinkButton is for display an image associated with a landmark in a new window, and all the landmarks are loaded by javascript and then by C#.
So to resume the behavior is: javascript code on the page calls a method in the SLight control passing a list of data, then the method create graphics with the data and also populate the mapTip information. Have no problem to bind data to static text fields (
<TextBlock Text="{Binding Path=[Event]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
), the issue is: how to add controls (HyperlinkButton or Image) dinamically to the maptip?
Thanks again.

dwtimmins, will check that thread.
Thx.
0 Kudos
JenniferNery
Esri Regular Contributor
This seem related: http://forums.arcgis.com/threads/29244-HELP-Set-MapTip-on-Graphic-not-GraphicsLayer. You can probably use another UserControl and put the logic for adding HyperlinkButton on SizeChanged.
0 Kudos