How can I attach a mouse event to a Run object in Silverlight?
I can attach a mouse-click event to a TextBlock object like this:
TextBlock tb = new TextBlock();
tb.Text = "click here";
tb.MouseLeftButtonDown += new MouseButtonEventHandler(tb_MouseLeftButtonDown);
But I would like to instead attach the mouse-click to individual Run objects inside the TextBlock object so that various parts of the TextBlock are clickable, like this:
TextBlock tb = new TextBlock();
tb.FontSize = 15;
Run run1 = new Run();
run1.Text = "This开发者_高级运维 should be clickable";
run1.MouseLeftButtonDown += new MouseButtonEventHandler(run1_MouseLeftButtonDown);
Run run2 = new Run();
run2.Text = " but not this.";
tb.Inlines.Add(run1);
tb.Inlines.Add(run2);
How can I attach a mouse event to a Run object?
You can not do this, but you can use hyperlink element instead.
Also there is another solution on my blog : http://www.jonathanantoine.com/2013/05/30/win8xaml-how-to-create-a-textblock-with-clickables-hyperlinks-in-it/
Regards.
精彩评论