46

I have a List View in which I have defined a custom cell as a user control.

In the custom cell I given user hyperlink, I am showing a WPF dialog when user clicks on a hyperlink.

I want WPF dialog comes just above the hyperlink..

Please let me know how can I acheive this or how to set the location of the dialog so that it just comes above the hyperlink.

Ashish Ashu
  • 14,169
  • 37
  • 86
  • 117

4 Answers4

86

Window.Left and Window.Top

var location = myTextBlock.PointToScreen(new Point(0, 0));
window.Left  = location.X;
window.Top   = location.Y - window.Height;
AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
Josh
  • 68,005
  • 14
  • 144
  • 156
20

You need to set the WindowStartupLocation to Manual (which is the default however) as well as setting the Top and Left property values.

Setting CenterScreen causes a window to be positioned in the center of the screen that contains the mouse cursor.

Setting WindowStartupLocation to CenterOwner causes a window to be positioned in the center of its owner window (see Owner), if specified. The owner window can be either another WPF window or a non-WPF window.

Source

Community
  • 1
  • 1
ChrisF
  • 134,786
  • 31
  • 255
  • 325
4

You would need to get the coordinates of the hyperlink and then set the window position as shown here:

http://blog.fossmo.net/post/How-to-set-the-windows-position-in-WPF.aspx

To get the relative/absolute positions of elements have a look here for some tips:

http://ivolo.mit.edu/post/WPF-Mouse-and-Point-Acrobatics.aspx

Igor Zevaka
  • 74,528
  • 26
  • 112
  • 128
-1

if you set .Left of the window more then monitor size (2000 works for me) window goes on second monitor and you can then "maximize"

maciej
  • 9
  • 9
    Hard coding values to make things work on your development machine is really bad practice. –  Jan 23 '18 at 17:19