简体   繁体   English

单击父窗口时的WPF模态无边界窗口效果

[英]WPF modal borderless window effect when click on parent window

I have a custom borderless window: 我有一个自定义的无边界窗口:

<Window x:Class="MyBorderlessWindow"
    ...
    WindowStyle="None"
    ShowInTaskbar="False" 
    WindowStartupLocation="CenterScreen"
    ResizeMode="NoResize"
    AllowsTransparency="True">

And I set the owner of my borderless window to a parent window, in order to make it modal: 然后将无边界窗口的所有者设置为父窗口,以使其成为模态:

// in a parent window
var myWindow = new MyBorderlessWindow();
myWindow.Owner = this;
myWindow.ShowDialog();

But when I switch apps and back, and click on the parent window, window effects are different. 但是,当我切换应用程序并返回并单击父窗口时,窗口效果有所不同。

If the child window is a normal style window, the child will be brought back to the topmost. 如果子窗口是普通样式窗口,则该子窗口将被带回到最顶部。

However, my custom borderless window will not be brought back to the topmost when I click on the parent window. 但是,当我单击父窗口时,我的自定义无边界窗口将不会回到最顶部。 I have to use alt + tab to switch to the child window manually. 我必须使用alt + tab手动切换到子窗口。

Is it possible to make my borderless window act like a normal modal window? 是否可以使我的无边界窗口像普通的模态窗口一样工作?

Did you try setting the Topmost property on the window? 您是否尝试在窗口上设置Topmost属性?

var myWindow = new MyBorderlessWindow();
myWindow.Owner = this;
myWindow.Topmost = true;
myWindow.ShowDialog();

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

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