Window mainWindow = Application.Current.MainWindow; mainWindow.Focus();
Window focusedWindow = Keyboard.FocusedElement as Window; if(focusedWindow != null) { // Do something with the focused window }This code gets the currently focused window and performs an action on it. The System.Windows.Window namespace belongs to the WPF (Windows Presentation Foundation) package library.