none
How can you use an embedded image on a Hyperlink button?

    Question

  •  I set my image's Build action to "embedded resource", then after compiling and using  Reflector, my public resource is: ISE_Portal.Assets.Pics.BlueChart.png.

     My XAML is: 

                                     <HyperlinkButton Width="36" Click="HyperlinkButton_Click" IsEnabled="{Binding bIsChartLinkEnabled}">
    <HyperlinkButton.Content>
    <Image Source="ISE_Portal.Assets.Pics.BlueChart.png" Width="20" Height="20" />
    </HyperlinkButton.Content>
    </HyperlinkButton>
    But the image does not appear.
    What am I doing wrong? Surely this is possible, non?
     Any help would be greatly appreciated!
        
    Monday, February 08, 2010 3:47 PM

Answers

  •  Hmm, neither worked, I ended up using vector templates instead (got to practice my awful art skills) :)

    I am left confused though.  What is the purpose of the "Embedded Resource" build option for the images?  It seems useless if we are supposed to use "Resource" to build.

     Are there any recommendations for performance of one solution over the other?  I used the vector templates since there potentially could have been 10 - 20 of these hyperlink buttons on the page.

    Friday, February 12, 2010 12:11 PM

All replies

  • The source string should be "[MyAssemblyName];component/[MyFolder/]BlueImage.png"
    Replace the placeholders with the right values (without the brackets []).
    Monday, February 08, 2010 3:58 PM
  •  Thanks Rene, although it didn't show the image, is my syntax wrong?

      <Image Source="ISE_Portal;component/Assets/Pics/BlueChart.png" Width="20" Height="20" />

    My Build setting is: Embedded Resource and my Copy to output directory is "Do not copy".

    Monday, February 08, 2010 4:00 PM
  • The Build Action has to be only "Resource". And the project / Assembly Name "ISE_Portal".
    Monday, February 08, 2010 4:41 PM
  •  Hmm, neither worked, I ended up using vector templates instead (got to practice my awful art skills) :)

    I am left confused though.  What is the purpose of the "Embedded Resource" build option for the images?  It seems useless if we are supposed to use "Resource" to build.

     Are there any recommendations for performance of one solution over the other?  I used the vector templates since there potentially could have been 10 - 20 of these hyperlink buttons on the page.

    Friday, February 12, 2010 12:11 PM
  • Hmm, strange. This always works for me without problems.
    Please don't forget to mark all the answers that helped you.
    Friday, February 12, 2010 2:45 PM
  • Are you using a Toolkit theme? Then that might be the issue, because some themes won't show HyperlinkButton Content when it's declared as XAML. I've just opened a work item as codeplex: http://silverlight.codeplex.com/WorkItem/View.aspx?WorkItemId=5580 ... Similarly, the mistake could also be that you defined your own style that would have a similar effect.
    Wednesday, March 03, 2010 10:22 AM
  •  Thanks mepfuso, but not using a toolkit theme, sorry to hear about the issue.  I'll just stick to compiling the pics as "Content" and that works fine.

    Wednesday, March 03, 2010 3:32 PM
  • The reason it is not working because you are missing a / at the start of path.

     

    Use

    <Image Source="/ISE_Portal;component/Assets/Pics/BlueChart.png" Width="20" Height="20" />

    instead of

    <Image Source="ISE_Portal;component/Assets/Pics/BlueChart.png" Width="20" Height="20" />

     

    Regards,

    Friday, July 09, 2010 9:29 AM