P/Invokeで手を汚す必要があります。WinAPIからこれらの関数が必要になります。
[DllImport("user32.dll")]
static extern IntPtr GetWindow(IntPtr hWnd, uint wCmd);
const uint GW_HWNDNEXT = 2;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsWindowVisible(IntPtr hWnd);
それらの使用方法:
private void Button_Click(object sender, RoutedEventArgs e)
{
// Get the WPF window handle
IntPtr hWnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
// Look for next visible window in Z order
IntPtr hNext = hWnd;
do
hNext = GetWindow(hNext, GW_HWNDNEXT);
while (!IsWindowVisible(hNext));
// Bring the window to foreground
SetForegroundWindow(hNext);
}