【发布时间】:2010-11-13 23:00:21
【问题描述】:
在我的应用程序中,我有一个用于绘制调试数据的窗口。当它加载时,我想在所有其他窗口后面“在后台”打开它。
实现这一目标的最佳方法是什么?
【问题讨论】:
在我的应用程序中,我有一个用于绘制调试数据的窗口。当它加载时,我想在所有其他窗口后面“在后台”打开它。
实现这一目标的最佳方法是什么?
【问题讨论】:
您是否有任何特殊原因不想以最小化状态显示窗口并允许用户显示它?如果以最小化状态显示窗口可以解决您的问题,请使用
<Window WindowState="Minimized" (...)>
【讨论】:
您可以使用以下代码:
[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);
}
来源:http://www.aeroxp.org/board/lofiversion/index.php?t4983.html
【讨论】:
<window>.Topmost 设置为true,那么什么也不会发生。我不想Activate()窗口,在使用上面的代码将它发送到后面之后似乎需要它。