none
WPF Image Hot Spot RRS feed

  • Question

  • I am trying to create a WPF app that has a map with hot spots.  Below is the xaml that I am working with.  

    <Viewbox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="MapsViewbox">
                <Canvas Name="MapsHotSpot"
                        Clip="F1 M 0,0L 800,0L 800,600L 0,600L 0,0" 
                        HorizontalAlignment="Stretch" 
                        VerticalAlignment="Stretch"
                        UseLayoutRounding="False">
                    <Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Canvas.Left="0" Canvas.Top="0">
                        <Image x:Name="Image" Source="/TestMap.png" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Canvas.Left="0" Canvas.Top="0">
                            <Image.RenderTransform>
                                <TransformGroup>
                                    <MatrixTransform Matrix="1,0,0,1,132,0"/>
                                </TransformGroup>
                            </Image.RenderTransform>
                        </Image>
                    </Canvas>
                </Canvas>
            </Viewbox>

    I am currently having the issue of the image not being shown.  When I remove all the view box and canvas tags the image show fine.  

    Thank you for your help in advance.


    Robert Johnston

    Thursday, July 5, 2012 5:49 PM

Answers

  • Hi,

    you can't "Stretch" things inside a ViewBox (as it is the primary purpose of the VB to stretch/shrink it's content to fit). Either discard the ViewBox or give the Canvas a Width and Height.

    Cheers
    Jürgen

    Thursday, July 5, 2012 6:04 PM

All replies

  • Hi,

    you can't "Stretch" things inside a ViewBox (as it is the primary purpose of the VB to stretch/shrink it's content to fit). Either discard the ViewBox or give the Canvas a Width and Height.

    Cheers
    Jürgen

    Thursday, July 5, 2012 6:04 PM
  • Give Image control Width and Height. That should solve the problem.

    Although following link is for silverlight but it could help you in developing Image Hotspot

    http://www.c-sharpcorner.com/uploadfile/bryianTan/silverlight-creating-image-map-with-hotspots/


    Gaurav Khanna | Microsoft VB.NET MVP

    Thursday, July 5, 2012 6:12 PM
  • Hi Sheldon _Xiao,

    can you please tell by what criteria you select "correct" answers or discard "wrong" ones. As much annoying it is to have an answer, which took a considerable amount of time to put here, not held worth a few seconds of time for marking by the original poster, as much it is discouraging to be downvoted by people who - form their job - should know better.

    I write this, as it is not the first time I see a 'not that easy to follow' selection of yours, but where I remember cases that were arguable or where are more than the one picked (your own) correct answers, this time you have chosen a wrong answer (the correct answer by the way is presented by the linked article).

    So, for solving Bob's problem and for not discouraging (contributors like) me: correct your proposal and stop deciding only on points (just a guessed answer to my initial question).

    Regards
    Jürgen

    NB: Your selection isn't wrong because you didn't choose my answer, but to "give Image control Width and Height" yields ... nothing (which I have tested as I do with most of my answers)


    Tuesday, July 10, 2012 7:02 AM
  • Hi Bob,

    Sorry for my mistake, I want to propose the reply who said "give fix size of root Canvas", becasue when canvas render in viewbox, it will render as default width and height, canvas size is 0, viewbox will not enlarge a 0 size child, so you could not see your image. you could provide fix size of canvas to fix this problem.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, July 10, 2012 7:43 AM
    Moderator
  • Hi Jurgen Rohr,

    Thank you for your help.


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 10, 2012 7:45 AM
    Moderator