Skip to content

Instantly share code, notes, and snippets.

@ImaginaryDevelopment
Created September 23, 2016 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ImaginaryDevelopment/cd14a3cb42732c290946b5be30d5a4a9 to your computer and use it in GitHub Desktop.
Save ImaginaryDevelopment/cd14a3cb42732c290946b5be30d5a4a9 to your computer and use it in GitHub Desktop.
BringToFrontAfterShowDialog
// 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