如何将鼠标事件附加到Silverlight中的Run对象?

时间:2010-06-29 12:31:02

标签: c# silverlight events mouse

我可以将鼠标单击事件附加到TextBlock对象,如下所示:

TextBlock tb = new TextBlock();
tb.Text = "click here";
tb.MouseLeftButtonDown += new MouseButtonEventHandler(tb_MouseLeftButtonDown);

但是我希望将鼠标单击附加到TextBlock对象内的各个Run对象,以便可以单击TextBlock的各个部分,如下所示:

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);

如何将鼠标事件附加到Run对象?

1 个答案:

答案 0 :(得分:0)

你不能这样做,但你可以改用超链接元素。

我的博客还有另一个解决方案:http://www.jonathanantoine.com/2013/05/30/win8xaml-how-to-create-a-textblock-with-clickables-hyperlinks-in-it/

问候。