How to send a WPF window to the back?

天大地大妈咪最大 提交于 2019-12-28 04:09:05

问题


In my application I have a window I use for plotting debug data. When it loads, I would like to open it "in the background", behind all other windows.

What's the best way to achieve this?


回答1:


You can use the following code:

[DllImport("user32.dll")]
static extern bool SetWindowPos(
    IntPtr hWnd,
    IntPtr hWndInsertAfter,
    int X,
    int Y,
    int cx,
    int cy,
    uint uFlags);

const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;

static readonly IntPtr HWND_BOTTOM = new IntPtr(1);

static void SendWpfWindowBack(Window window)
{
    var hWnd = new WindowInteropHelper(window).Handle;
    SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}

Source: http://www.aeroxp.org/board/lofiversion/index.php?t4983.html




回答2:


Is there any particular reason you don't want to show the window in minimized state and allow user to show it? If showing window in minimized state solves your problem, use

<Window WindowState="Minimized" (...)>


来源:https://stackoverflow.com/questions/1181336/how-to-send-a-wpf-window-to-the-back

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!