简体   繁体   English

创建 WPF 弹出窗口

[英]Creating WPF popup

I want to create a modal popup.我想创建一个模式弹出窗口。 So far I have made a window which I create when I need it.到目前为止,我已经制作了一个 window,我会在需要时创建它。 But I don't think that is the right way to do this.但我认为这不是正确的做法。 The problem is, everytime I call it, it opens about 20px to the right and 20px lower than previous one.问题是,每次我调用它时,它都会向右打开大约 20px,比上一个低 20px。 It's annoying.这很烦人。 Is this default behaviour or am I doing something wrong here?这是默认行为还是我在这里做错了什么?

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

Also, I want it to be centered if that's possible?另外,如果可能的话,我希望它居中吗?

Below will center the your dialog box to the owner/parent form.下面将您的对话框居中到所有者/父窗体。

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

Below are the alternative if you want to try.如果您想尝试,以下是替代方案。 If you want to Center it to the screen use 'CenterScreen'如果要将其居中显示在屏幕上,请使用“CenterScreen”

Manual - The startup location of a Window is set from code, or defers to the default Windows location.手动 - Window 的启动位置由代码设置,或遵循默认的 Windows 位置。

CenterScreen - The startup location of a Window is the center of the screen that contains the mouse cursor. CenterScreen - Window 的启动位置是包含鼠标 cursor 的屏幕中心。

CenterOwner - The startup location of a Window is the center of the Window that owns it, as specified by the Window.Owner property. CenterOwner - Window 的启动位置是拥有它的 Window 的中心,由 Window.Owner 属性指定。

You want to set the WindowStartupLocation member of the Success window.您要设置 Success window 的WindowStartupLocation成员。 Sounds like CenterOwner is the value you want.听起来 CenterOwner 是您想要的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM