Using Tags for Simple Hyperlinks in Silverlight 1.0

One of the features that I was glad to see added to Silverlight 1.0 was the Tag attribute which can be used to add any metadata (hidden) text to any visual element.  I have been using it to add hyperlink features to my applications.  Here's how I do it:

  1. I put the hyperlink URL in the Tag attribute of an element:
    <TextBlock Width="14.8" Height="14.8" Text="i" TextWrapping="Wrap" FontFamily="Webdings" Foreground="#FF71FF0D" Canvas.Left="135.2" Canvas.Top="85.2" Cursor="Hand" Tag=""/>
  2. I then have a JavaScript function AddLinks() that I call when the scene is loaded or when I load additional XAML:
    function AddLinks(visual)
        if (visual.Tag != "")
            visual.AddEventListener("MouseLeftButtonDown", ClickPageLink);
            visual.Cursor = "Hand";

        if (visual.toString() == "Canvas")
           for (var i = 0; i < visual.children.count; i++)

    function ClickPageLink(sender, eventArgs)
    {, "_blank");

This lets me add hyperlinks to any visual element in a scene.

Comments (4)

  1. Adam Kinney says:

    I like this method and most likely will be usin it in the future.  Thanks for sharing 🙂

  2. Synergist says:

    As you can see, I have been experimenting with posting video on my blog now that I have a HD Video Camera

  3. 花间蕊 says:

    来源:MichaelS.ScherotterBlog 在Silverlight中有一个非常好的特性就是Tag属性,它可以被用来给任何可视化的元素添加任意的文本。我们可以使用它来给我…

Skip to main content