WPF: How do I make a custom modal dialog flash?

后端 未结 2 1757
攒了一身酷
攒了一身酷 2021-01-19 00:24

Normally when you open a Modal Dialog and try to click on it\'s parent window the Modal Dialog\'s titlebar flashes. When creating a custom, borderless, chromeless, window in

2条回答
  •  醉梦人生
    2021-01-19 00:54

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            var retVal = IntPtr.Zero;
    
            switch (msg)
            {
                case UnsafeNativeConstants.WM_NCACTIVATE:
                    retVal = UnsafeNativeMethods.DefWindowProc(hwnd, UnsafeNativeConstants.WM_NCACTIVATE, new IntPtr(1), new IntPtr(-1));
                    AssociatedObject.UpdateTitlebar((int)wParam == 1 ? true : false);
                    handled = true;
                    break;
            }
    
            return retVal;
        }
    

    The WndProc I have hooked up in a custom behavior that's attached to my window. It calls an internal method on my window that will update the color of the Titlebar appropriately.

    Thanks to @Hans Passant for pointing me in the right direction.

提交回复
热议问题