- 在窗口的XAML文件中添加以下属性:
ShowInTaskbar="False"
这将使窗口不显示在任务栏上,并且不会出现在Alt+Tab切换列表中。
- 在窗口的代码中,覆盖OnSourceInitialized方法并使用Win32 API来将窗口从Alt+Tab列表中删除:
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
// Get this window's handle
IntPtr hWnd = new WindowInteropHelper(this).Handle;
// Get the extended window style
int exStyle = (int)GetWindowLong(hWnd, GWL_EXSTYLE);
// Set the WS_EX_TOOLWINDOW style
exStyle |= WS_EX_TOOLWINDOW;
SetWindowLong(hWnd, GWL_EXSTYLE, (IntPtr)exStyle);
}
// Win32 API declarations
private const int GWL_EXSTYLE = -20;
private const int WS_EX_TOOLWINDOW = 0x80;
[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);