I’m developing an app for Windows Phone 7 and I faced quite a strange problem with the standard TextBox: I cannot type “Space”. All other keys work just fine but the “Space” key is simply ignored with no errors popping up.
I populate the textbox dynamically. Here’s the code responsible for this:
var newComment = new TextBox()
{
Width = 378,
MaxLength = 128,
AcceptsReturn = true,
/*Tag = ... ,*/
/*Style = ... ,*/
/*BorderBrush = ... ,*/
Margin = new Thickness(-12, 0, 0, 0)
};
newComment.InputScope = new InputScope();
newComment.InputScope.Names.Add(new InputScopeName() { NameValue = InputScopeNameValue.Text });
newComment.KeyDown += (sender, args) =>
{
if (args.Key == System.Windows.Input.Key.Enter)
{
args.Handled = true;
/* ... */
}
};
container.Items.Add(newComment);
I commented out some stuff that (I think) is irrelevant. The “container” is an instance of ListBox.
When I put a breakpoint inside the “KeyDown” event handler and press “Space”, the args.Key is “Unknown” (args.PlatformKeyCode is “160”). I have textboxes in other places of my app (not dynamic though) and they work just fine.
Tested on emulator as well as on the device (I have HTC Mozart if this makes any difference). Developing for Mango.
It turned out that the problem was caused because of the
TextBoxbeing inside aButton(because I needed to be able to tap on the whole “thing”). Placing it outside of theButtonfixed the issue.