Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Text input in custom Silverlight control
2 replies. Latest Post by MIG3919 on June 26, 2009.
(0)
MIG3919
Member
0 points
2 Posts
06-22-2009 7:34 AM |
I've just started playing with Silverlight. I've created a custom display for text-like information by starting with a canvas and adding multiple TextBlock and Rectangle objects, and it looks perfect.
I want it to be editable, so I've added a cursor which moves around according to cursor key presses (as captured by the Page_KeyDown event). So far so good!
Now I want to capture keyboard key presses, so that I can put typed text into my control. Using Page_KeyDown is not an option, because I need the actual character (as typed on any keyboard, e.g. American, French, English, even Greek?). The only way I can see of getting a character from a keyboard in Silverlight is by using a TextBox and checking the _TextChanged event, but I don't want a TextBox to be visible - I want to use my own display.
Is it possible to do this by inheriting my control from the TextBox object (I need to get the characters, but not display the TextBox)? Or is there another way?
I thought this would be the easy bit...
Thanks,
MIG
lawazia
126 points
58 Posts
06-22-2009 10:04 AM |
You can change the Control Template of the TextBox to give it a desired look, without changing the control behavior.
06-26-2009 3:42 AM |
Thanks for the information - I'm doing some reading! I've had some success with using a zero-width TextBox and intercepting its key data, and I'm concerned that I need to change the functionality too much to use a modified TextBox only, but I'll give it a try. I'd rather do it properly than use a bodge.