Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the location of a WPF window?

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.

like image 729
Ashish Ashu Avatar asked Apr 29 '10 04:04

Ashish Ashu


People also ask

How do I set the WPF window to the center of the screen?

Centring Windows To open a new window and have it centred on the screen, set the WindowStartupLocation property to CenterScreen. You can do this using the XAML or in code before the window is displayed. Run the program and click the button to see the result.

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.

How does WPF implement navigation?

To package content for navigation, WPF provides the Page class. You can navigate from one Page to another declaratively, by using a Hyperlink, or programmatically, by using the NavigationService. WPF uses the journal to remember pages that have been navigated from and to navigate back to them.


2 Answers

Window.Left and Window.Top

var location = myTextBlock.PointToScreen(new Point(0, 0)); window.Left  = location.X; window.Top   = location.Y - window.Height; 
like image 168
Josh Avatar answered Sep 22 '22 23:09

Josh


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

like image 25
ChrisF Avatar answered Sep 22 '22 23:09

ChrisF