8

I have some problems with an own styled WPF Window on Windows 8.1. I wrote a simple transparent WPF Window with a WindowChrome for default windows drag behaviors:

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300" Width="300" Background="Transparent"
        AllowsTransparency="True" WindowStyle="None">
    <WindowChrome.WindowChrome>
        <WindowChrome />
    </WindowChrome.WindowChrome>
    <Border Background="Gray" CornerRadius="20">
        <Grid>
        </Grid>
    </Border>
</Window>

Windows 8.1 Settings:

  • 2 monitors with extended desktop
  • Taskbar only visible on primary desktop

Repro:

  1. Start the WPF application
  2. Move the window on the secondary screen
  3. Maximize the window on the secondary screen (for example by docking the window on the top)
  4. Restore and drag the window from the secondary screen to the primary screen

--> The taskbar icon will disappear exactly when the mouse enters on the primary screen!

If you do the same repro again the icon reappears.

I also tried to use .NET 4.5 or .NET 4.5.1!

Can anyone explain this problem?

Thank you!

Thomas H.
  • 83
  • 4
  • Are both set to the exact same resolution? – Chris W. Jan 22 '14 at 19:22
  • No I have tested it with 1920x1200 and 1280x1024. But if I set both to the same resolution (2x 1280x1024), I got the same result. I also testet it on windows 8, the taskbar icon also disappears. – Thomas H. Jan 23 '14 at 08:07
  • I have a similar issue but here the taskbar "icon" disappears when moving from primary to any secondary screen i.e. as soon as moving to another monitor. I have 3 monitors. All monitors are same resolution. Also running 8.1. – nietras Feb 12 '14 at 16:49
  • I have already posted a bug report on microsoft connect: http://connect.microsoft.com/VisualStudio/feedback/details/814471/taskbar-icon-disappears-when-windowchrome-is-used-with-a-transparent-wpf-window-on-windows-8-1 – Thomas H. Feb 13 '14 at 19:06
  • Yep. Same thing here on Windows 8.0. This thing appears too buggy for production. This looked like a great idea, but I guess I'm going to drop back to DwmExtendFrameIntoClientArea unless there's a new release. – Quark Soup Mar 26 '14 at 00:54
  • @ThomasH. really nasty bug, so if you got a solution, let me hear – punker76 Apr 05 '14 at 21:24

2 Answers2

4

after some trial and error debugging i figured out, that the window visibility is setting to false, then update the system menu and after that setting to true.

i think this is not necessary and produces this nasty issue

here is the method at WindowChromeWorker

private void _UpdateSystemMenu(WindowState? assumeState)
{
    const MF mfEnabled = MF.ENABLED | MF.BYCOMMAND;
    const MF mfDisabled = MF.GRAYED | MF.DISABLED | MF.BYCOMMAND;

    WindowState state = assumeState ?? _GetHwndState();

    if (null != assumeState || _lastMenuState != state)
    {
        _lastMenuState = state;

        bool modified = _ModifyStyle(WS.VISIBLE, 0);

        IntPtr hmenu = NativeMethods.GetSystemMenu(_hwnd, false);
        if (IntPtr.Zero != hmenu)
        {
            // change menu items
            ...
        }

        if (modified)
        {
            _ModifyStyle(0, WS.VISIBLE);
        }
    }
}

so you can try take a look into my branch of

WPF Shell Integration Library (Ex)tended Edition

original source can be found here

also here is a little test application

hope that helps

punker76
  • 14,326
  • 5
  • 58
  • 96
2

It seems that this bug only appears when you set WindowStyle="None" on your WPF window. Moreover, this option also breaks Modern apps which are snapped to the side when maximizing you application. It may seem weird, but setting WindowStyle is not required when using WindowChrome to remove window borders, so you can safely skip it.

The only caveat is that you cannot use AllowTransparency (but it's allright, as you should not use it in the first place due to extensive performance problems with this option).

ghord
  • 13,260
  • 6
  • 44
  • 69