Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Canvas (which acts like a mini - details window) and I have a StackPanel which has some HyperLink elements in it. Each HyperLink is positioned differently and is dynamically added to the Canvas. I show the Canvas (the mini details window) as soon as the user clicks on it.

Now I wrote the logic to show the Canvas on the location (getting the X, Y co-ordinates by calling the MouseEventArgs.GetPosition(null) method). I then set the margin of the Canvas according to the X, Y co-ordinates. However. It is not showing up as expected. I want the Canvas to be shown exactly below the link. Can anybody help me out?
Posted

1 solution

When you get the coordinates of your Mouse on click, grab the label control that exists in that position. Then you just have to offset your panel based on the labels position instead of the mouse position.

Here is a thread on how to achieve that: WPF Get Elements under mouse[^]
 
Share this answer
 
v2
Comments
Pankaj Nikam 14-Nov-12 22:18pm    
I understood your solution and when I tried accessing the margin properties of the label, I get a zero margin on all sides. Please guide me.
fjdiewornncalwe 15-Nov-12 10:53am    
Margin is likely going to be 0 on a label. You need to use the position properties(ie. Left, Right, Top, Bottom) to get orientation values.
Pankaj Nikam 15-Nov-12 11:13am    
Thanks a lot for your reply :)
I am newbie to WPF. Please guide me to access the properties you mentioned, Left, Right, Top, Bottom as I am unable to get them (Label.Right etc).
Pankaj Nikam 29-Nov-12 4:52am    
Thanks your answer helped.
fjdiewornncalwe 29-Nov-12 11:10am    
You are very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900