talia
talia

Reputation: 159

cannot write in textbox wpf

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.

Upvotes: 4

Views: 6092

Answers (3)

dodgy_coder
dodgy_coder

Reputation: 13033

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.

Upvotes: 2

talia
talia

Reputation: 159

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!

Upvotes: 11

benPearce
benPearce

Reputation: 38333

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

Quite weird!

Upvotes: 0

Related Questions