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.
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With