5

I have a requirement that specifies that a notification tray application that uses WPF must (based on some conditions) pop-up a window that is globally modal. This should prevent the user from doing anything (even outside of the Tray application) until they have satisfied some other conditions at which time it will enable the close button and allow the user to close it.

How does one make such a window? I have the window displaying and it evaluates the conditions and whatnot, but it is only modal to the application (i.e. it only blocks execution and UI for the application it is running under.

I imagine I could create a borderless window and maybe disable the minimize functionality, but they would still be able to access the start menu. Any takers? What I am striving for functionality-wise is similar to the Windows UAC/Admin privilege request window.

This is not a duplicate of the question provided by the duplicate box at the top. That question pertains to Windows Forms and is not applicable to WPF. As it happens I received an answer that worked well for me, and it was not the answer to the question provided above. Not that it matters really, but I would like the duplicate tag taken off. I like to think that I research my questions pretty well before posting, and adding that tag implies that I do not.

EDIT

This question is not a duplicate of the question that was linked int he Duplicate Question box. That question was answered with in a Windows Forms flavor, and I am using WPF, a completely different UI framework.

CodeWarrior
  • 7,388
  • 7
  • 51
  • 78
  • That sounds fairly obnoxious and I'm not certain you can take over the desktop without nasty hacks to keep your screen in the foreground. – user7116 Feb 12 '13 at 14:45
  • I don't write the requirements. I can only argue against them, and implement them when I get shot down. – CodeWarrior Feb 12 '13 at 14:46
  • To an extent it is. Requirement is that there is no way (at least no easy way like Alt+Tab) to get out of it... I had hoped there was some fairly simple way that I was not aware of to create a system modal window. – CodeWarrior Feb 12 '13 at 14:51
  • Have you considered running Windows in embedded mode with no explorer shell? There wouldn't be anything else to `alt-tab` to – paul Feb 12 '13 at 14:54
  • 1
    Well this is an app to nag our users into putting their time into the time system. They have a lot of other applications installed and in use. Personally I would fix the time system to make it easier and more appealing instead of nagging them to death about it. – CodeWarrior Feb 12 '13 at 14:57
  • 1
    @CodeWarrior link time-logging into the payroll system. no nagging required. – paul Feb 12 '13 at 15:00

2 Answers2

6

Use the Window.ShowDialog() method. More info can be found here

See the second comment by sixlettervariables.

CodeWarrior
  • 7,388
  • 7
  • 51
  • 78
Alex Shtoff
  • 2,520
  • 1
  • 25
  • 53
  • That only makes the window modal to the application, not the rest of the system. – CodeWarrior Feb 12 '13 at 14:45
  • 2
    `Window.ShowDialog()` plus a `LockSetForegroundWindow` call would likely "help" but wouldn't handle all of the cases. – user7116 Feb 12 '13 at 14:47
  • After a meeting with the product owner, we decided that making it difficult to get around the window will be enough for now. I will go with the above as it will make it difficult for at least a non-power user. – CodeWarrior Feb 12 '13 at 15:21
  • 4
    "See the second comment by sixlettervariables." this is not very useful. I cannot find such a comment anywhere. If that comment had something important to say, please include it in the answer. – Mike Nakis Jul 11 '19 at 08:07
1

One solution could be to make a semi transparent WPF window that covers the entire screen (actually you should say: all screens) and show the modal window using Window.ShowDialog() with the owner being that window. All you need to do then is prevent task switching (which is not an easy task), but maybe doing that is enough?

Something like UAC does - for example like in the answer to this?

Community
  • 1
  • 1
Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • Yeah I was thinking about that. How hard it is to intercept Ctl+Shift+Esc and Alt+Tab? Are those key combinations so highly reserved that handling them in the application does nothing? I will have to think on that... – CodeWarrior Feb 12 '13 at 14:50
  • I didn't read this fully, but it actually seems that it isn't easily possible: http://stackoverflow.com/questions/886076/how-can-i-intercept-all-key-events-including-ctrlaltdel-and-ctrltab – Thorsten Dittmar Feb 12 '13 at 14:58
  • No, not easily. That was actually one of my problems when I got this requirement, but managers don't want to hear "That will be kind of hard/messy". – CodeWarrior Feb 12 '13 at 15:00
  • I know :-) Luckily I don't have to implement it. Hope I could help a bit anyway. – Thorsten Dittmar Feb 12 '13 at 15:25