wpfxaml.net-4.5windows-8.1window-chrome

Taskbar icon disappears when WindowChrome is used on Windows 8.1


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:

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!


Solution

  • 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