在HyperLink下方显示WPF画布
我有一个Canvas
(其作用类似于一个迷你详细信息窗口),而我有一个StackPanel
,其中包含一些HyperLink
元素.每个HyperLink
的位置都不同,并被动态添加到Canvas中.一旦用户单击,我就会显示Canvas
(迷你详细信息窗口).
现在,我编写了逻辑以在位置上显示Canvas(通过调用MouseEventArgs.GetPosition(null)
方法获取X,Y坐标).然后,根据X,Y坐标设置Canvas
的边距.然而.它没有出现按预期的方式.我希望画布"显示在链接的正下方.有人可以帮我吗?
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?
当您单击鼠标时获得鼠标的坐标时,请抓住该位置上存在的标签控件.然后,您只需要根据标签位置而不是鼠标位置来偏移面板即可.
这是有关如何实现该目标的主题: WPF在鼠标下获取元素 [ ^ ]
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[^]