views:

368

answers:

3

I am trying to make a WPF app (regular Windows app, not XBAP or Silverlight). I want the main app window to support transparency, and show through the desktop below.

But when I specify ToolTip text on a Button, the ToolTip appears beneath (z-order) the main window!

I have a screenshot where: * Another app overlapps and blocks view of the partially transparent main window. * The tooltip from my button appears in front of the other app. * Where the tooltip is not in front of the other app, it is behind the partial transparency.

I read elsewhere that this is a known problem with the WPF engine for 32-bit XP and does not occur in Vista.

What I am looking for is a fix/workaround.

A: 

Try the .SetValue(Canvas.ZIndex, 100) method on the UIElement you want on top. (I used 100, only to force the element to the top)

Janie
Doesn't work when I'm not using a Canvas to render the window.
Jeff B
Using a Canvas has nothing to do with the Canvas.ZIndex DependencyProperty (un-intuitive as that sounds)
Janie
A: 

This is a know problem of WIndows XP and WPF (e.g. see here on Connect).

You can avoid the problem by not using a layered window (use one with a frame). I think another solution would be to set the whole window TopMost=true, but for me, that's not a very good solution and I'm not sure about that.

I don't know if MS is tackling this issue, because I think it's quite deep in the graphic layer of XP.

dalind
My impression is that its not in the XP graphics layer at all - it looks more like WPF draws an entire second desktop layer atop the native XP (Win32) graphics - but clips it to fit where WPF should be 'visible'. This is the way early 3D and movie accellerators worked if they were 'windowed'.
Jeff B
Well, that I don't know. But I know it's not just a clipping problem. Even if the Tooltip would be entirely inside the WPF- Window Area, it can happen that the Tooltips are behind the application. You can see that with a tool like Snoop, or if the Tooltip is long enough to go over the borders of the WPF-Window.
dalind
A: 

Ok- here's what I found as a workaround:

The problem with ToolTips goes away when the window is also made TopMost.

But I don't want my window to be topmost, so I only do it when my window has keyboard focus:

private void Window_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
 this.Topmost = true;
}

private void Window_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
 this.Topmost = false;
}

Then I use a binding to enable each ToolTip only when my window is Topmost:

ToolTipService="{Binding ElementName=MainWindow, Path=Topmost}"

This turns off the ToolTip except when it works right. Don't really need tooltips when my window isn't in focus anyway.

Only annoying thing now is that the on/off binding has to be done on every element that defines a Tooltip.

Jeff B