开发者

WPF window focus

I have an application (say App1). It has a datagrid that holds data items. If I right mouse click on a data item it brings up a "Item Details" window. However, App1 doesn't do this directly. Instead, it talks to another application, say App2, and App2 actually displays the "Item Details" window. My problem is as follows: 1. Bring up App2 then minimize it to the task bar. 2. On App1, right mouse click a data item to bring up the "Item Details" window. 3. The "Item Details" window comes up to the front, but it doesn't have the focus (the title bar is gray). App1 still has the focus. 4. If I close the "Item Details" window and repeat Step 2 again, this time the "Item Details" window not only comes up to the front but also has the focus. 5. If I do Step 1 again, then I get the same result as in Step 3.

I also noticed that I have this problem on some computers but not on others.

I have tried various methods to get the focus on the "Item Details" window but failed. The Focus() method just returns false.

(In fact, at first the "Item Details" window wouldn't even come to the front, but I set "Topmost" to true when the window is initialized and set it back to fals开发者_开发技巧e after the contents are rendered, which forces the window to the front.)


I Suppose. Why do you need to set TopMost? Instead you should set App2's owner as App1.

HTH


Can't set App1 as App2's owner. They are unrelated applications. The only way App1 can communicate with App2 is by Windows messages. I tried to set App2 as "Item Details" window's owner but it didn't solve the problem.


Found solution to this problem. App1 has to call AllowSetForegroundWindow(...) to enable App2 to set foreground window. See MSDN documentation on AllowSetForegroundWindow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜