views:

26

answers:

2

Hi everybody! I 'm running into a situation i don't understand and want somebody to enlighten me if possible.

Created a WPF application. For sake of simplicity consider this application to be one window. I put some controls on this window, amongst others there is a TextBox control (let's call it TB).

There is a requirement that this TB must always have the focus (in case someone types something or something is read through the barcode-scanner it should appear there).

I thought implementing this with the help of a timer: every second the focus is transferred to the TB.

Until now everything works fine (as expected).

The weird thing is the following: let's say a new user wants to use this window, so she has to sign in. I thought implementing this with a new Window object (let's call it W2), calling it this way:

W2.ShowDialog();

This W2 window should be modal (bear in mind that the timer still executes).

The crazy thing is that under Windows Vista this works perfectly as expected (this means W2 is modal and the user can to what she should do on W2), BUT on Windows XP as soon as the user wants to type something in a textbox of W2 the focus is set back to TB on the initial Window (as far as i can interpret: this means W2 is not modal!!!? am i right?).

How can i overcome this situation?

Is this the right approach?

Thanks in advance

+1  A: 

Make sure to set the Owner property of W2 to your main Window.

From the referenced docs:

When you open a child window by calling ShowDialog, you should also set the Owner property of the child window.

Reed Copsey
To be honest: i didn't set this. I think you 're right! This must be the missing part. But on the other side: why is it working on Windows Vista?
Savvas Sopiadis
@Sawas: For some reason, this doesn't seem to behave exactly the same in XP - in Vista/7, not setting this doesn't usually cause problems (though, technically, it should be set there, too)
Reed Copsey
+1  A: 

I am not sure this setting-the-focus-back-every-few-seconds is such a good idea. It is always possible that some input will come in the interval between a lost and got focus state (and be lost). Alternative solutions are catching the PreviewKeydown event on the form that the TB resides on and somehow set the output of a barscanner to the TB too.

Dabblernl
Thanks very much for pointing me into this direction. I have to dig around to see how to implement using this technique. +1 from me! Thanks again very much
Savvas Sopiadis