I am working on a silverlight web application. It interacts with the module that sends SMS. I want to limit the text to 160 and show a counter. I did it like this:
public partial class SendSMSView { public SendSMSView() { InitializeComponent(); ApplyTheme(); } protected void tbMessage_KeyDown(object sender, KeyEventArgs e) { count = 160 - this.tbMessage.Text.Length; this.lblCount.Content = count.ToString(); } }
This works fine for all keys except backspace and delete. Of course, this is done like this. I dug up more about this and tried to override the keydown event, so I added the following code snippet:
public class CustomTextBox : TextBox { public CustomTextBox(): base() { } protected override void OnKeyDown(KeyEventArgs e) { e.handler=false; base.OnKeyDown(e);
In the OnKeyDown function, I get all the registered strokes. Setting Handler to false here does not help, and yet I cannot get backspace to run tbMessage_KeyDow.
I want to somehow call the tbMessage_KeyDow function from // this place from there for the backup space.
I searched the MSDN and found that IsInputKey could be overridden to return true, so that onKeyDown also responds to it, but my framework does not have IsInputKey or PreviewKeyPress. Is there a way around the return key registered as an input key, or to call tbMessage_KeyDow [which is a very rude approach]? Please, help.
whizzyifti
source share