views:

576

answers:

3

I have written a simple MSN-style program that will send and retrieve messages using WCF. The main form contains a Textbox to type in the message to be sent. In the background the application polls the server every few seconds for new messages. When a new message is received a new window is opened to display it. This has to be done on the UI thread using the Dispatcher class.

The problem is that when the new window is shown, the focus shifts away from the TextBox, so that typing is interrupted. This is very annoying! In MSN Messenger it is possible to continue typing your own message while receiving one. How is it done?

As a workaround I postpone the popup with the new message while the TextBox has focus, but there should be a better way!

+1  A: 

You can show windows without stealing focus: http://stackoverflow.com/questions/156046/show-a-form-without-stealing-focus-in-c

It's a bit cludgy and it'd be nice if it were built in - but it works.

Paul Alexander
Thanks for the link. It pointed me in the right direction.
Dabblernl
+3  A: 

The answer is simple: Since .NET 3.5 SP1 WPF forms have a ShowActivated property. Set this to false and the form thus marked won't steal focus anymore!

Dabblernl
A: 

You could set the Focusable property of the window to false.

codymanix
Not in this case. The user must be able to interact with the form
Dabblernl