【发布时间】:2010-12-30 03:07:01
【问题描述】:
当我运行它并单击链接时,我希望浏览器打开并转到谷歌,但 什么都没有发生:
<Window x:Class="TestHyperlink2343.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBlock>
You and read this or
<Hyperlink NavigateUri="http://www.google.com">go to google</Hyperlink>
etc.
</TextBlock>
</Grid>
</Window>
然后我将上面的代码替换为以下代码,仍然没有任何反应。然而,令人惊讶的是,如果我右键单击链接,它会转到 google:
<Window x:Class="TestHyperlink2343.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBlock>
You and read this or
<Hyperlink MouseDown="Hyperlink_MouseDown">go to google</Hyperlink>
etc.
</TextBlock>
</Grid>
</Window>
private void Hyperlink_MouseDown(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.com");
}
为什么这些示例没有按预期工作?我怎样才能获得一个简单的超链接来工作,因为用户已经习惯了他们在网络浏览器中工作(左键单击、打开浏览器、转到站点)?
附录
我通过创建自己的超链接没有这样的超链接元素解决了这个问题:
<TextBlock Text="More info at wikipedia"
TextDecorations="Underline"
MouseDown="TextBlock_MouseDown_Wikipedia"/>
private void TextBlock_MouseDown_Wikipedia(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
System.Diagnostics.Process.Start("http://www.wikipedia.com");
}
奇怪的是,超链接不那么容易工作。
【问题讨论】: