Jaa


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.

Comments

  • Anonymous
    October 06, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/10/06/using-tags-for-simple-hyperlinks-in-silverlight-10/

  • Anonymous
    October 19, 2007
    I like this method and most likely will be usin it in the future.  Thanks for sharing :)

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

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