Skip to main content

Microsoft Silverlight

Answered Question Text input in custom Silverlight controlRSS Feed

(0)

MIG3919
MIG3919

Member

Member

0 points

2 Posts

Text input in custom Silverlight control

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
lawazia

Member

Member

126 points

58 Posts

Answered Question

Re: Text input in custom Silverlight control

You can change the Control Template of the TextBox to give it a desired look, without changing the control behavior.

MIG3919
MIG3919

Member

Member

0 points

2 Posts

Re: Text input in custom Silverlight control

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.

 Thanks,

 MIG

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities