Created
September 23, 2016 13:11
-
-
Save ImaginaryDevelopment/cd14a3cb42732c290946b5be30d5a4a9 to your computer and use it in GitHub Desktop.
BringToFrontAfterShowDialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// consider doing this in the Load or Window_ContentRendered events instead | |
// options to clean up temporary things like frontmost could be done in Window_Initialized | |
// using options from http://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf | |
public new bool? ShowDialog() | |
{ | |
var t = new System.Threading.Tasks.Task(() => | |
{ | |
// wait for the window to show from show dialog | |
Task.Delay(1000); | |
try | |
{ | |
this.Dispatcher.Invoke(() => | |
{ | |
this.Activate(); | |
this.Topmost = true; | |
this.Topmost = false; | |
this.Focus(); | |
}); | |
} | |
catch (Exception ex) | |
{ | |
// log exception if desired. | |
} | |
}); | |
t.Start(); | |
return base.ShowDialog(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment