当我运行它并点击链接时,我希望浏览器打开并转到谷歌,但没有任何反应:
<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>
Run Code Online (Sandbox Code Playgroud)
然后我用以下代码替换了上面的代码,但仍然没有任何反应。然而,令人惊讶的是,如果我右键单击链接,它会转到谷歌:
<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");
}
Run Code Online (Sandbox Code Playgroud)
为什么这些示例没有按预期工作,我怎样才能让一个简单的超链接工作,因为用户已经习惯了它们在 Web 浏览器中工作(左键单击、打开浏览器、转到站点)?
我通过创建自己的超链接来解决这个问题,没有像这样的超链接元素:
<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");
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,超链接不能这么容易地工作。
在MSDN指出:
超级链接导航只能发生,但是,如果任一一个的直接或间接的父超链接是导航主机,包括NavigationWindow,帧,或可承载的XBAP任何浏览器(它包括的Internet Explorer 7,微软的Internet Explorer 6和Firefox 2.0 +)。有关详细信息,请参阅导航概述中的导航主机主题。
没有看到您的更多代码,我不知道这是否适用于您的情况。
归档时间: |
|
查看次数: |
4841 次 |
最近记录: |