How to set the location of a WPF window?

前端 未结 4 2120
半阙折子戏
半阙折子戏 2020-12-06 04:31

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

相关标签:
4条回答
  • 2020-12-06 04:34

    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

    0 讨论(0)
  • 2020-12-06 04:34

    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"

    0 讨论(0)
  • 2020-12-06 04:47

    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

    0 讨论(0)
  • 2020-12-06 04:52

    Window.Left and Window.Top

    var location = myTextBlock.PointToScreen(new Point(0, 0));
    window.Left  = location.X;
    window.Top   = location.Y - window.Height;
    
    0 讨论(0)
提交回复
热议问题