Detect the active window in an WPF application
Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);