Click here to Skip to main content
12,890,181 members (48,126 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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
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[^]
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.
Marcus Kramer 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.
Marcus Kramer 29-Nov-12 11:10am
You are very welcome.
Pankaj Nikam 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2017
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