WPF ShowDialog单击所有者窗口事件

时间:2018-09-18 16:26:02

标签: c# wpf xaml

我的英语不是很好,希望您能帮助我回答这个问题,快点,WPF在ShowDialog()时,单击其他父窗体触发的事件可以捕获吗?

例如,系统自己的MessageBox(在父窗口上单击)将具有闪烁的动画。

我想捕获事件,谢谢

1 个答案:

答案 0 :(得分:0)

First of all, whatever your goal is in the end, it can probably be reached in a different way. I really encourage you to take several steps back, think twice and try to approach the problem from some different side before actually doing what you asked.

As for your question, you don't have such an event in WPF. There is an answer, but there is no easy way. You'll have to guess and go low-level. And the guess will depend on the version of Windows it runs on.

Anyway, you need to check the sequence of Window Messages that your owner form receives. In Windows 8.1 owner form receives WM_WINDOWPOSCHANGING with lParam pointing to a structure whose flags are at least 0x13 : SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE.

Of course, to get this information you need to override WindowProc of your window first, which in WPF is a separate fun. And additionally, the combination of parameters may also happen in other circumstances so you'll have to make sure to track somehow that you have a modal dialog open so that this kind of window message actually means the attempt to activate owner window.

It's low-level windows management, so you can do essentially everything. But I really advise you to think several times before going in this direction.