WPG / Silverlight Hyperlink Image

I am new to both Silverlight and WP7. I am trying to link an image using HyperlinkButton and setting its contents to an image. However, it just makes my image disappear.

Playback:

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

I have tried many properties and nothing works for me. Both elements work interdependently. Is this possible in WP7? This is an external URI. I am looking for documentation and did not find anything that helped.

Your comments and suggestions are welcome.

+4
source share
3 answers

This is a little weird in that you cannot directly put an image as control content. The topic was explored here during beta testing.

Peter Torr previously suggested using the glass pane as the content of a hyperlink. This worked at the time, but for some reason does not seem to work.

With that said, Richard Wu defined a job that was supposed to use the background property of hyperlinks. I confirmed that this 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> 

Perhaps you should pay attention to the problem, which will be discussed on the proposal forum or connect.

As for alternatives to the hyperlink, the Matt option with the image and gesture looks workable. You can also use the Button and update its appearance in Blend.

+6
source

It looks like you are trying to make the image of a web page launch when clicked.

Only to launch a webpage can you use WebBrowserTask . If I were you, I would wrap the image in a GestureListener ( from the toolkit ) and run the task in the 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(); } 
+5
source

You need to change the HyperlinkButton style to include any content, not just text. Here is an example style:

 <Style x:Key="BrowserHyperlinkButtonStyle" TargetType="HyperlinkButton"> <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}" /> <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}" /> <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}" /> <Setter Property="FontWeight" Value="Normal" /> <Setter Property="Background" Value="{StaticResource TransparentBrush}" /> <Setter Property="BorderBrush" Value="{x:Null}" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="VerticalContentAlignment" Value="Top" /> <Setter Property="Padding" Value="{StaticResource PhoneTouchTargetOverhang}" /> <Setter Property="TargetName" Value="_blank" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="HyperlinkButton"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver" /> <VisualState x:Name="Pressed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneSubtleBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Disabled"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="FocusStates"> <VisualState x:Name="Focused" /> <VisualState x:Name="Unfocused" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <ContentControl Name="ContentElement" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" /> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 
0
source

All Articles