One possible way would be to scan the list of open windows in the application and check which one of them has IsActive = true
:
Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
Not sure if there may be more than one active window if, for example, there's a modal dialog showing, in which case, the owner of the dialog and the dialog itself might be active.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…