Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP7/Silverlight Hyperlink Image

I am new to both Silverlight and WP7. I have been attempting to hotlink an image by using a HyperlinkButton and setting its content to an Image. However, this just makes my Image disappear.

To reproduce:

  1. Create a new Windows Phone Panorama Application.
  2. On the MainPage.xaml replace the Rectangle with an Image, setting the source to ApplicationIcon.png.
  3. Then, surround it with a HyperlinkButton.
<HyperlinkButton NavigateUri="http://www.bing.com" TargetName="_blank">
   <Image Source="ApplicationIcon.png"/>
</HyperlinkButton>

I have tried numerous properties and nothing works for me. Both items work interdependently. Is this possible in WP7? It is an external URI. I have search for documentation and found nothing that's helped.

Your comments and suggestions are appreciated.

like image 654
nullable Avatar asked Dec 21 '22 21:12

nullable


2 Answers

This is a bit of an oddity in that you can't directly place an Image as the control's content. The topic was explored here during beta.

Peter Torr's had previously suggested using a stackpanel as the hyperlink's content. This did work at the time, but does not appear to be working at the moment for some reason.

With that said, Richard Woo identified a work around which was to use the hyperlinks background property. I confirmed this still works as follows:

    <HyperlinkButton Height="310" HorizontalAlignment="Left" Margin="206,202,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="200" >
        <HyperlinkButton.Background>
            <ImageBrush ImageSource="SplashScreenImage.jpg"/>
        </HyperlinkButton.Background>
    </HyperlinkButton>

It may be worth raising this as an issue to be looked into on the suggestions forum or connect.

As far as alternatives to hyperlink go, Matt's option with an Image and gesture looks workable. You could also use a Button and retemplate it's appearance in Blend.

like image 116
Mick N Avatar answered Dec 30 '22 07:12

Mick N


It looks like you're trying to make an image launch a webpage when tapped.

THe only way to launch a web page is to use the WebBrowserTask. If I were you I'd wrap an Image in a GestureListener (from the toolkit) and launch the task on a tap event.

Like this:

xaml:

    <Image Source="images/appbar.favs.addto.rest.png" Stretch="None" >
        <Controls:GestureService.GestureListener>
            <Controls:GestureListener Tap="GestureListener_Tap" />
        </Controls:GestureService.GestureListener>
    </Image>

cs:

    private void GestureListener_Tap(object sender, GestureEventArgs e)
    {
        var wbt = new WebBrowserTask();
        wbt.URL = "http://www.stackoverflow.com/";
        wbt.Show();
    }
like image 26
Matt Lacey Avatar answered Dec 30 '22 07:12

Matt Lacey