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

发布于 2024-09-07 15:22:56 字数 623 浏览 0 评论 0原文

我可以将鼠标单击事件附加到 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 对象?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-09-14 15:22:56

您不能这样做,但可以使用超链接元素代替。

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

问候。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文