Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#/WPF, how to make a window (created with Window.ShowDialog()) title bar blink when clicking its parent window (like MessageBox does)?

I'm trying to create a custom MessageBox by using a WPF Window that is called with ShowDialog().

So far, I've managed to implement everything, except for one thing.

As you know, when you use MessageBox.Show("text"); you cannot set the focus or click the parent window (the one that called the MessageBox). If you do try to click the parent window, the MessageBox will blink briefly in order to alert you that you must close if first.

Windows created with Window.ShowDialog();, however, do not show that behavior. In fact, while you cannot set the focus to the parent window, the child (called with ShowDialog()) will never blink briefly.

My question is, is there any way to implement that in WPF? I've been searching for an answer but I must admit, I am stumped.

Thanks everyone!

like image 783
Ze Pedro Avatar asked Oct 26 '10 19:10

Ze Pedro


2 Answers

You need to set the Owner of the modal window correctly, e.g. using the following code from within the owning window:

Window win = new SomeModalWindow();
win.Owner = this;
win.ShowDialog();
like image 96
Dirk Vollmar Avatar answered Oct 11 '22 13:10

Dirk Vollmar


You would have to set Owner property of the child Window to the parent Window. See the MSDN Documentation here.

like image 24
CodingGorilla Avatar answered Oct 11 '22 13:10

CodingGorilla