locked
Programically remove shift when textbox is focused

    Question

  • Hi all,

    When a textbox is focused and the textbox is empty, "shift" is automatically set on the keyboard, so that the first key you enter will be capitalized.

    Is there a way to remove this functionality?

    I figured that if I could trigger an event on textbox focus, check if the textbox is empty I could change the modifier keys of the keyboard to "none", but I am clueless as to how I can set modifier keys. Keyboard.Modifier = Modifier.none does not work (Modifier does not have a setter).

    Anyone have an idea? C# WP8 Silverlight project.

    private void MyTextBox_OnGotFocus(object sender, RoutedEventArgs e)
            {
                if (MyTextBox.Text.Length == 0)
                {
                    // Change keyboard modifier to ModifierKeys.none
                }
            }
    Saturday, September 13, 2014 10:36 AM

Answers

  • If you want that when you textbox got focus then user should not be able to input then please make textbox read only from properties windows and if you want textbox to take just numbers, name, email, url, password then you can do this MyTextBox.InputScope = "numbers" or else whatever you want.

    Here is a link to help you:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.inputscope(v=vs.95).aspx

    also this:

    http://msdn.microsoft.com/en-us/library/System.Windows.Controls.TextBox(v=vs.95).aspx

    Muhammad Asad.

    • Marked as answer by Cato L Saturday, September 13, 2014 11:08 AM
    Saturday, September 13, 2014 10:57 AM
  • Ended up changing the input scope of the TextBox to password. Fixed it! :D

    Thanks for the help Muhammad Asad!

    • Marked as answer by Cato L Saturday, September 13, 2014 11:08 AM
    Saturday, September 13, 2014 11:08 AM

All replies

  • If you want that when you textbox got focus then user should not be able to input then please make textbox read only from properties windows and if you want textbox to take just numbers, name, email, url, password then you can do this MyTextBox.InputScope = "numbers" or else whatever you want.

    Here is a link to help you:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.inputscope(v=vs.95).aspx

    also this:

    http://msdn.microsoft.com/en-us/library/System.Windows.Controls.TextBox(v=vs.95).aspx

    Muhammad Asad.

    • Marked as answer by Cato L Saturday, September 13, 2014 11:08 AM
    Saturday, September 13, 2014 10:57 AM
  • Ended up changing the input scope of the TextBox to password. Fixed it! :D

    Thanks for the help Muhammad Asad!

    • Marked as answer by Cato L Saturday, September 13, 2014 11:08 AM
    Saturday, September 13, 2014 11:08 AM
  • Hmm sometimes this sort of things happens:D
    Saturday, September 13, 2014 7:38 PM