1

I am looking for a way to work around what I think is a bug with WPF. This is the most simplified example of the issue. Clearly in this case it defeats the purpose of Window.Topmost but it makes the issue very plain. In implementing a System.Windows.Window:

    protected override void OnDeactivated(EventArgs e) {
        this.Topmost = false;
        base.OnDeactivated(e);
    }

This will not reliably prevent the Window or its contents from continuing to draw OVER another, newly activated application. For instance if I click in the text area of Notepad, the WPF Window will draw over Notepad. If I click at the top of Notepad (and this is typical for most other applications I've tried) my WPF Window will draw over until MOUSEUP occurs and only if it occurs soon enough. I can repeatedly MOUSEDOWN and the window stays topmost as long as my MOUSEUP doesn't come too quickly behind it. However there are a few situations in which it reliably draws behind, depending on where I click in what application, or if I click a second application it will never draw on top of that one.

Note: In practice what I am trying to do is use a transparent overlay which "sticks" to a windows Form. So in that case it already is deactivated 99% of the time as the user interacts with the Form. Since I cannot reliably turn off TopMost for the window, the non-transparent bits of my application continue to float on top of other applications. Forcing the window to render does not change anything.

Attached screenshot shows how the bug does not recur on clicking a second application, but it stays on top of the first window (the red bits are from my application).

Snapshot of Window sandwiched with Topmost==false

H.B.
  • 166,899
  • 29
  • 327
  • 400
Josh Sutterfield
  • 1,943
  • 2
  • 16
  • 25
  • you're probably gonna have to hack into the winapi. this stuff is a pain in the arse. (100% consistency is difficult.) – Jake Berger Feb 24 '12 at 22:20
  • Update: I gave up on Topmost and was able to get my my WPF window "subjugated" properly to winforms via WindowsInteropHelper as advised here: http://stackoverflow.com/questions/2599053/how-to-set-win32-window-as-owner-of-wpf-window – Josh Sutterfield Feb 28 '12 at 15:24

0 Answers0