WPF Borderless Window issues: Aero Snap & Maximizing

前端 未结 6 1628
独厮守ぢ
独厮守ぢ 2020-12-03 03:37

I\'ve created a borderless WPF window by setting the following window properties in XAML:

... WindowStyle=\"None\" AllowsTransparency=\"True\" ...

6条回答
  •  被撕碎了的回忆
    2020-12-03 04:27

    You can specify the maximize region by handling the WM_GETMINMAXINFO Win32 message. The code here shows how to do that. It will solve issues #5 and #6.

    Note that there are a few things that I would do differently, such as returning IntPtr.Zero instead of (System.IntPtr)0 in WindowProc and making MONITOR_DEFAULTTONEAREST a constant. But that's just coding style changes, and doesn't affect the net result.

    Also make sure to pay attention to the update where the WindowProc is hooked during the SourceInitialized event instead of OnApplyTemplate. That's the better place to do it. If you're implementing a class derived from Window, then another option is to override OnSourceInitialized to hook the WindowProc instead of attaching to the event. That's what I normally do.

提交回复
热议问题