tags:

views:

491

answers:

1

How can I refer to active Window of WPF application in C#, using something like ActiveForm property in WinForms?

+3  A: 

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.Cast<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.

Aviad P.