Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #62 – How to Create a Hyperlink

Hyperlinks are a graphic or string that connects readers to another web site when clicked. Generally these are a few words that are identified by a blue color and a underline. Here is an example of a hyperlink:

Click Me

In Silverlight Hyperlinks can be created through the HyperlinkButton control.

Here is an example of a how to declare a HyperlinkButton control in XAML:

<HyperlinkButton Content="Click Me" NavigateUri="http://www.silverlight.net">
</HyperlinkButton>

Couple notes:

  1. Content is what is displayed to the user.
  2. NavigateUri is the destination the user is taken too when the link is clicked.

When run you will see this:

image

You can target the link to open the link in a new page or the same page by setting the TargetName property.

  1. TargetName = _blank, _media, _search = Open the link in a new window
  2. TargetName = _parent, _self, _top, “” = Open the link in the window the link was clicked.

Example opening a new page:

<HyperlinkButton Content="Click Me" TargetName="_blank" NavigateUri="http://www.silverlight.net">
</HyperlinkButton>

Opening the same page:

<HyperlinkButton Content="Click Me" TargetName="_self" NavigateUri="http://www.silverlight.net">
</HyperlinkButton>

Additionally, the Hyperlink does not have to be represented by text. You can use any control such as a Image, etc. by setting the HyperlinkButton.Content. For example:

<HyperlinkButton NavigateUri="http://www.silverlight.net">
    <HyperlinkButton.Content>
        <Canvas>
            <Rectangle Width="100" Height="100" Fill="Black" Stroke="Blue" StrokeThickness="2" ></Rectangle>
            <TextBlock Canvas.Top="40" Canvas.Left="25">Click Me</TextBlock>
        </Canvas>
    </HyperlinkButton.Content>
</HyperlinkButton>

As shown when run:

image

Thank you,
--Mike Snow

 Subscribe in a reader

Comments

Microsoft Weblogs said:

Hyperlinks are a graphic or string that connects readers to another web site when clicked. Generally

# October 16, 2008 5:14 PM

GearWorld said:

And how do you use this in Blend 2 ?

# October 16, 2008 8:19 PM

GearWorld said:

Ops I did write something in the wrong page :)  Forget the previous thing I said about Blend 2.

# October 16, 2008 8:21 PM

Steve Strong said:

Is there a TargetName to open the link in a new Tab of the browser?

# October 16, 2008 11:47 PM

Silverlight news for October 17, 2008 said:

Pingback from  Silverlight news for October 17, 2008

# October 17, 2008 3:36 AM

Dew Drop - October 17, 2008 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - October 17, 2008 | Alvin Ashcraft's Morning Dew

# October 17, 2008 9:33 AM

mike.snow said:

Steve- Sorry, I do not think there is.

# October 17, 2008 12:59 PM

Community Blogs said:

In this issue: Tim Heuer, Pete Brown, Mike Taulty, NikhilKothari, Dan Wahlin, Laurence Moroney, Arturo

# October 18, 2008 1:25 AM

Wie man einen Hyperlink erstellt at Blog von J??rgen Ebner said:

Pingback from  Wie man einen Hyperlink erstellt at Blog von J??rgen Ebner

# October 20, 2008 3:18 AM

2008 October 21 - Links for today « My (almost) Daily Links said:

Pingback from  2008 October 21 - Links for today &laquo; My (almost) Daily Links

# October 21, 2008 4:34 AM

algeee said:

Or alternatively if you want to create a hyperlink from, for example an image, you can simply create a uri using your desired path and navigate to that URI inside an appropriate event.

Uri uri =

new Uri("http://www.silverlight.net");

         System.Windows.Browser.HtmlPage.Window.Navigate(uri);

# October 28, 2008 6:03 AM

Visual Web Developer Team Blog said:

Silverlight Tip of the Day #66 Title: How to copy XAML for Silverlight from Expression Designer Silverlight

# November 3, 2008 1:40 PM

Silverlight Tips of the Day - Blog by Mike Snow said:

The purpose of this post is to create an outline summary all the blogs from my Silverlight tips of the

# January 2, 2009 5:56 PM

o UAU nosso de cada dia said:

essa lista eu copiei desse blog bárbaro (acompanhe por RSS você também): uma lista de dicas super úteis

# January 3, 2009 6:25 AM

jin_u as blog » Blog Archive » ??????????????? ??? ?????? said:

Pingback from  jin_u as blog  &raquo; Blog Archive   &raquo; ??????????????? ??? ??????

# January 14, 2009 8:58 PM

abhishekshukla85 said:

Thanks

# October 25, 2009 2:49 AM

puckoff7337 said:

Thanks, I found this to be a very useful summary of information!

# April 15, 2010 11:13 PM

cleanpro said:

I could get the hyperlinkbutton to work until i realized that in sl4 you have to include the target parameter... Good article.

# October 9, 2011 7:20 PM

Hyperlinkbutton silverlight | Grossadjusting said:

Pingback from  Hyperlinkbutton silverlight | Grossadjusting

# January 8, 2012 10:02 PM