Is there any way to stop a WPF Popup from repositioning itself when it goes off-screen?
I found this old question, but it didn\'t get a proper answer to it. Is there
there is no way on wpf framework to put Popup out of screen , but you can force popup position by calling "SetWindowPos" via p/invoke:
#region P/Invoke imports & definitions
private const int HWND_TOPMOST = -1;
private const int HWND_NOTOPMOST = -2;
private const int HWND_BOTTOM = 1;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOACTIVATE = 0x0010;
private const int GW_HWNDPREV = 3;
private const int GW_HWNDLAST = 1;
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
private static extern int SetWindowPos(IntPtr hWnd, int hwndInsertAfter, int x, int y, int cx, int cy, int wFlags);
#endregion
private void updateposition(Item item)
{
if (item.IsOpen)
{
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(item.popup.Child)).Handle;
SetWindowPos(hwnd, 0, (int)item.WorkPoint.X, (int)item.WorkPoint.Y, (int)item.popup.Width, (int)item.popup.Height, SWP_NOSIZE | SWP_NOACTIVATE);
}
}