I have a lot (about 30) TextBoxes in the same window and I want to register all of them to the same PreviewKeyDown Event. Is there any easy way of signing all of them without the need to sign each of the textBoxes (in the XAML code) individualy?
Thanks in advance,
Gil.
brunda kPosted Jun 13, 2012, 8:33 AM
http://www.koders.com/csharp/fidA8BD3088D2F2C65644CA511813DC5153C91C52A2.aspx?s=file
gil elgrablyPosted Jun 13, 2012, 2:23 PM
gil elgrablyPosted Jun 13, 2012, 7:05 AM
Well thanks, but were do I put this code?
I'm receiving this (static) error:
"RegisterClassHandler is a Method but used like a type"brunda kPosted Jun 13, 2012, 4:55 AM
EventManager.RegisterClassHandler(typeof(TextBox),
TextBox.PreviewKeyDown,
new System.Windows.Input.KeyEventHandler(TextBox_PreviewKeyDown));
VulpesPosted Jun 13, 2012, 4:41 AM
If you select the first TextBox, find its PreviewKeyDown event in the Properties Box and double click it, this will create your skeleton handler.
If you then find the PreviewKeyDown events for the other TextBoxes in the Properties Box, you'll see that there's a drop down box from which you can select the handler that you've created thereby wiring up all the TextBoxes to the same handler.