Creating a WPF Popup

I want to create a modal popup. So far I have created a window that I create when I need it. But I do not think this is the right way to do this. The problem is that every time I call it, it opens about 20 pixels to the right and 20 pixels below the previous one. This is annoying. Is this the default behavior or am I doing something wrong here?

Success win1 = new Success(); win1.ShowDialog(); 

Also, I want it to be centered, if possible?

+4
source share
2 answers

Below is your dialog box in the form of owner / parent.

 Success win1 = new Success(); win1.Owner = this; // For example , see the parent window here win1.WindowStartupLocation = WindowStartupLocation.CenterOwner; win1.ShowDialog(); 

Below are alternatives if you want to try. If you want to Center it on the screen, use CenterScreen

Manually. The initial location of the window is set with the code or redirected to the default location of Windows.

CenterScreen - the place where the window starts - this is the center of the screen that contains the mouse cursor.

CenterOwner - the window launch location is the center of the window to which it belongs, as indicated by the Window.Owner property.

+9
source

You want to set the WindowStartupLocation element of the Success window. It seems like CenterOwner is the value you want.

+3
source

All Articles