模态对话框未显示在其他窗口之上 [英] Modal Dialog not showing on top of other windows

查看:33
本文介绍了模态对话框未显示在其他窗口之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Window.ShowDialog() 在我的 WPF (MVVM) 应用程序中打开一个模式窗口,但它让我可以使用 Windows 任务栏 (Windows 7) 导航到其他窗口.>

考虑一下:我的应用程序中打开了 3 个非模态窗口.现在其中之一使用 Window.ShowDialog() 打开一个模态窗口.我还将 Application.MainWindow 设置为模式窗口的所有者.这是因为我正在使用 MVVM 消息传递,并且打开新窗口的消息处理程序集中在 App.xaml.cs 中.窗口确实以模态打开 - 没有问题.但是,Windows 7 允许我从任务栏切换到其他应用程序窗口.这会导致模态窗口位于另一个窗口后面的情况,而我不想这样做.

只要我打开模态窗口,我就不能在其他窗口上做任何事情,但是如果模态窗口在打开时始终保持在顶部,那就太好了.有没有办法在模式打开时禁用任务栏切换?仅供参考 - 从应用程序启动的所有打开的窗口在任务栏上都显示为单独的条目.

提前致谢!

解决方案

没有任何代码可以以此为基础,但听起来您在 Window 上遗漏了一些属性已经创建并期望 ShowDialog应用额外的对话"语义:

Window window = new Window(){Title = "模态对话框",ShowInTaskbar = false,//不在任务栏上显示对话框Topmost = true,//确保我们总是在最前面ResizeMode = ResizeMode.NoResize,//移除多余的标题栏按钮所有者 = Application.Current.MainWindow,};window.ShowDialog();

I am using Window.ShowDialog() to open a modal window in my WPF (MVVM) application, but it lets me navigate to other windows using the Windows taskbar (Windows 7).

Consider this: I have 3 non-modal windows open in my application. Now One of these opens a modal window using Window.ShowDialog(). I also set Application.MainWindow as the owner of the modal window. This is so because I am using MVVM messaging and the message handler to open a new window is centralized in App.xaml.cs. The window does opens modally - no issues there. However, Windows 7 allows me to swtich to the other application windows from the taskbar. This leads to a situation where the modal window goes behind another window, which I prefer not to have.

I can't do anything on other windows as long as I have the modal open, but it would be nice if the modal window always remained on top as long as it's open. Is there a way I can disable taskbar switching when the modal is open? FYI - all open windows launched from the app appear as separate entries on the taskbar.

Thanks in advance!

解决方案

There isn't any code to base this off of, but it sounds like you have left off some properties on the Window you've created and expected ShowDialog to apply additional "dialog" semantics:

Window window = new Window()
{
    Title = "Modal Dialog",
    ShowInTaskbar = false,               // don't show the dialog on the taskbar
    Topmost = true,                      // ensure we're Always On Top
    ResizeMode = ResizeMode.NoResize,    // remove excess caption bar buttons
    Owner = Application.Current.MainWindow,
};

window.ShowDialog();

这篇关于模态对话框未显示在其他窗口之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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