public static void SetWindowPlacement(IntPtr windowHandle, WindowPlacement placement)
{
// Check if the handle is valid
HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle");
// If the debugger is attached and the state of the window is ShowDefault, there's an issue where the window disappears
if (Debugger.IsAttached && placement.ShowCmd == WindowStates.ShowNormal)
placement.ShowCmd = WindowStates.Restore;
// Set the window placement
if (!NativeMethods.SetWindowPlacement(windowHandle, ref placement))
throw new Win32Exception("Couldn't set the window placement.");
}