开发者

Is TextBox behavior correct

Why TextBox is using e.Handled = true in order to prevent specific characters from being typed.

Don't we have a better way?

Isn't this a wrong design?

Currently I want to not receive KeyDown event if specific TextBox is in focus is there a good way to do this?Or I'll have to check is the OriginalSource the TextBox I want...

Edit:

As It seems that my original question is a bit confusing Let me reform it.

开发者_如何学CLets suppose we have a Canvas and textbox as a child of canvas. I registered for keyDown event of canvas to do something very interesting there.

I don't want to receive keydown events when user is typing in textBox though. Is there a way to do this without involving e.OriginalSource?


If you want to prevent any input you can (in fact, should) also set ReadOnly = true instead of listening to the KeyDown event.

If you want to selectively prevent key strokes, listening to KeyDown and setting e.Handled is the only way.

However, selectively preventing keystrokes is bad for usability; don’t do it. Instead, use the Validating event of the text box control to validate the user input.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜