none
How to create an Image hyperlink in MVVM

    Question

  • Hi Everyone,

    I am working with MVVM model and need to have an image link. I have my png image in a Images folder and want to use it in a hyperlink. Do I need to add this to the view as a resource first or do something before I can use my image? The BuildAction=Resource, CopytoOuputDirecotry = Copy Always.

    the view is in a folder called Views and Views and Images are in the same silverlight application

    How can I use my image in my xaml? At the moment I have this:

                        <HyperlinkButton  Content="View Map" NavigateUri="{Binding Path=Details.Location}" TargetName="_blank" >
                            <HyperlinkButton.Background>
                                <ImageBrush ImageSource="/Images/externallink.png"/>
                            </HyperlinkButton.Background>
                        </HyperlinkButton>

    Probably is only a matter of find the rirht relative url I am not sure

    Thursday, April 19, 2012 6:53 AM

Answers

  • Thanks it does help plus I had my path wrong =( I need to first put /assembly;component/Images/externallink.png

    But your idea of putting together the textbloc and image it works fine with me =)

     

    Many thanks =)

    Thursday, April 19, 2012 8:57 AM

All replies

  • Hi,

    "Copy Always" is not a must, it can be "Copy if newer"

    Modified your code like the following:

    <HyperlinkButton NavigateUri="{Binding Path=Details.Location}" TargetName="_blank" >
        <Grid>
            <Image Source="/Images/externallink.png" 
                   HorizontalAlignment="Center" 
                   VerticalAlignment="Center" />
            <TextBlock Text="View Map" 
                       HorizontalAlignment="Center" 
                       VerticalAlignment="Center"/>
        </Grid>
    </HyperlinkButton>

    Hope can help.

    Thursday, April 19, 2012 8:25 AM
  • Thanks it does help plus I had my path wrong =( I need to first put /assembly;component/Images/externallink.png

    But your idea of putting together the textbloc and image it works fine with me =)

     

    Many thanks =)

    Thursday, April 19, 2012 8:57 AM