WPF 弹出窗口出现在其他桌面窗口之上,如何只出现在 WPF 主窗口之上? [英] WPF Pop up is appearing over other desktop windows, how to only appear on top of the WPF main window?

查看:73
本文介绍了WPF 弹出窗口出现在其他桌面窗口之上,如何只出现在 WPF 主窗口之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有网格的 WPF 主窗口,并且我添加了一个 WPF 弹出窗口,以便在单击按钮时向用户询问额外信息.但问题是,当其他桌面窗口移动到弹出窗口上时,弹出窗口覆盖了其他桌面窗口.如何解决此问题,以便弹出窗口仅位于 WPF 主窗口的顶部,而不是其他桌面窗口.当设置为始终在顶部时,弹出窗口的行为就像任务管理器!

I have a WPF main window that has a grid and i have added a WPF pop up to ask the user for extra info when a button is clicked. But the problem is that when other desktop windows are moved over the pop up, the pop up covers the other desktop windows. How to fix this so the pop up is only top most of the WPF main window and not other desktop windows. The pop up is behaving like the task manager when set to always on top!

如果您使用以下代码,您将看到弹出窗口位于顶部.因此,将任何其他桌面窗口移到弹出窗口上,弹出窗口将覆盖其他桌面应用程序!请注意,我不想使用 StaysOpen="False".

If you use the below code you will see that the pop up stays on top. So move any other desktop window over the pop up and the pop up will cover the other desktop application! Note that i do not want to use StaysOpen="False".

<Grid>
    <Popup Name="myPopup" Placement="Center" IsOpen="True">
        <StackPanel Background="Green" >
            <TextBox Width="200" Margin="0,0,10,0"/>
            <Button Name="closePopupBtn" Content="close" Width="100" />
        </StackPanel>
    </Popup>
</Grid>

推荐答案

您已经在弹出窗口中设置了 Owner 属性.在您的弹出窗口中,

You have set the Owner property in the popup window. In your Popup Window,

this.owner = instanceOfParentWindow;

这也与您的问题相似.

弹出窗口总是在顶部

在这里他们创建一个自定义弹出窗口使用 user32.dll

Here they create a custom popup using user32.dll

这篇关于WPF 弹出窗口出现在其他桌面窗口之上,如何只出现在 WPF 主窗口之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆