C#中的超链接的TextBlock:没有任何反应,当我点击它 [英] C# Hyperlink in TextBlock: nothing happens when I click on it
本文介绍了C#中的超链接的TextBlock:没有任何反应,当我点击它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的C#独立的应用程序,我想让用户点击,将推出自己喜欢的浏览器中的链接。
In my C# standalone application, I want to let users click on a link that would launch their favorite browser.
System.Windows.Controls.TextBlock text = new TextBlock();
Run run = new Run("Link Text");
Hyperlink link = new Hyperlink(run);
link.NavigateUri = new Uri("http://w3.org");
text.Inlines.Add(link);
正确显示的链接。
The link is displayed correctly.
当我将鼠标移到它,链接变成红色
When I move the mouse over it, the link becomes red.
问题:当我点击它,什么都不会发生。
PROBLEM: When I click it, nothing happens.
难道我忘了什么东西?我是否需要实施某种方法来真正让链接被打开?
Did I forget something? Do I need to implement some kind of method to really let the link be opened?
推荐答案
您需要处理的超级链接的 RequestNavigate
事件。下面是这样做的快捷方式:
You need to handle the hyperlink's RequestNavigate
event. Here's a quick way of doing it:
link.RequestNavigate += (sender, e) =>
{
System.Diagnostics.Process.Start(e.Uri.ToString());
};
这篇关于C#中的超链接的TextBlock:没有任何反应,当我点击它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文