Reputation: 9858
Sometime, Window.Activate()
not working in other system.
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(y => y.IsActive) ?? Application.Current.Windows.OfType<Window>().FirstOrDefault();
if (window != null)
window.Activate();
I want a solution which should not fail in any system and also want to know the main cause of this.
Upvotes: 3
Views: 2038
Reputation: 4881
It can fail if you call it from non-UI thread. In that case you should to wrap call into dispatcher.
Application.Current.Dispatcher.Invoke(() =>
{
///.... UI stuff
});
Upvotes: 2