4
votes

I have a WPF project (creating dll). The text boxes that added, (or the listboxs) will only accept, COPY, PASTE, DELETE, and BACKSPACE.I do not know why the textboxs have this behavior. The system receives all of the events (KEYUP, KEYDOWN, PREVIEWKEYUP, PREVIEWKEYDOWN, but won't change the text if characters are typed.

The TEXTCHANGED event only fires for the Delete, Paste, etc.

The textbox is enable and NOT readonly.

Any help would be appreciated. thanks, talia.

3
Hi Talia - it's unclear from your question whether you have mysteriously acquired textboxes with this behaviour, and "cannot write in textbox wpf" is the problem, or you would like to create textboxes like this, and want some suggestions as to how. Please could you clarify? - Lunivore
I do not know why the textboxs have this behavior. i would like to write in side the textbox. - talia
Could you please give an example of how are you actually creating them. - n535
yes, just add it from the toolbox. <Textbox Higth="23" Margn="100,0,58,22" Name="textBox1" VerticalAlignment="Bottom" /> - talia

3 Answers

11
votes

adding this:

Window window1 = new Window(); 
System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(window1); 
window1.Show(); 

should fix the bug.

also add a reference to WindowsFormsIntegration.

thanks everyone!

2
votes

I had this same problem and then realised that I had handled the KeyDown event on the parent Window (and also set e.Handled to true). This in effect prevented any child controls from seeing KeyDown events.

0
votes

I have had this situation before, my only solution was to create a new solution / project and copy the code across.

Quite weird!