Silverlight HyperlinkButton NOT Working at ALL

2019-08-27 07:35发布

I'm trying to implement the Siverlight HyperlinkButton according to this documentation:

<HyperlinkButton Content="Click here to learn about Silverlight"
                 NavigateUri="http://www.silverlight.net" 
                 TargetName="_blank" 
                 Margin="10,60,0,0"/>

But, when I build and click it, it shows nothing.

2条回答
神经病院院长
2楼-- · 2019-08-27 07:56

My guess would be that you have not enabled external navigation for the Silverlight object. If you haven't a security exception will be getting thrown when you click the link, but you may be catching it without knowing. This is described in the remarks section of your above link.

To enable navigation edit your Silveright host page (E.G. index.html) and add the following param under the Silverlight object

<param name="enableNavigation" value="true" />

By default Silverlight generates the .html page each time you run/debug so you will lose the param. To get around this make a copy of the .html file in the same directory but with a different name or manually specify which .html file to use in the project settings.

http://msdn.microsoft.com/en-us/library/dd833071(v=vs.95).aspx

Update:

This works for Chrome, Firefox and IE8. It does not work for IE9. You can test this in IE by using the developer tools. Links work with Document Mode IE8 but throw an Unauthorized Access exception when using Document Mode IE9.

Update #2:

To get it to work in IE9 you can force it to use the IE8 Document Mode. To do this you need to remove the DOCTYPE tag and add a meta tag. E.G.

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <meta http-equiv="x-ua-compatible" content="IE=8">
    .
    .

Instead of

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    .
    .
查看更多
The star\"
3楼-- · 2019-08-27 08:01

You Should Visit This Link For Hyperlink Button Issue or ..... it's defiantly working.....

<UserControl x:Class="HyperlinkButton2.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="300" Height="100">
    <Canvas x:Name="LayoutRoot" Background="White">
        <HyperlinkButton x:Name="hbtnTest" TargetName="_blank" Content="SilverlightShow" NavigateUri="http://www.silverlightshow.net" Canvas.Top="40" Canvas.Left="30"></HyperlinkButton>
    </Canvas>

Using the HyperlinkButton control in Silverlight

查看更多
登录 后发表回答