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="https://blogs.msdn.com/synergist"/>
  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++)        {            AddLinks(visual.children.getItem(i));        }     } }function ClickPageLink(sender, eventArgs) {     window.open(sender.Tag, "_blank"); }

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