Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modal Dialog not showing on top of other windows

Tags:

wpf

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!

like image 806
Pratz Avatar asked Jun 20 '11 21:06

Pratz


People also ask

Is modal dialog is blocking window?

A modal window creates a mode that disables the main window but keeps it visible, with the modal window as a child window in front of it. Users must interact with the modal window before they can return to the parent application. This avoids interrupting the workflow on the main window.

What is the difference between a modal and a dialog?

Dialog (dialogue): A conversation between two people. In a user interface, a dialog is a “conversation” between the system and the user. Mode: A special state of the system in which the same system has somewhat different user interfaces.

Is a modal a dialog?

Definition: A modal dialog is a dialog that appears on top of the main content and moves the system into a special mode requiring user interaction. This dialog disables the main content until the user explicitly interacts with the modal dialog.


1 Answers

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(); 
like image 98
user7116 Avatar answered Sep 20 '22 11:09

user7116