如何将鼠标事件附加到 Silverlight 中的 Run 对象?
我可以将鼠标单击事件附加到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能这样做,但可以使用超链接元素代替。
我的博客上还有另一个解决方案: 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.