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:
<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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With