Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows WPF C#4.0
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 8-Nov-12 5:52am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
v2
Comments
Pankaj Nikam at 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.
Marcus Kramer at 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 at 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 at 29-Nov-12 4:52am
   
Thanks your answer helped.
Marcus Kramer at 29-Nov-12 11:10am
   
You are very welcome.
Pankaj Nikam at 30-Nov-12 0:38am
   
:)

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

  Print Answers RSS
0 OriginalGriff 693
1 George Jonsson 370
2 BillWoodruff 337
3 Sergey Alexandrovich Kryukov 259
4 Garth J Lancaster 240
0 Sergey Alexandrovich Kryukov 10,764
1 Maciej Los 5,474
2 OriginalGriff 5,472
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web03 | 2.8.141030.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100