locked
How to write the code for entering only 4 digits in password box if the user tries to enter 5th character it will automatically goto my home page? RRS feed

  • Question

  • Hi,

    I am developing universal windows 10 apps,in one of my project i used the password box,but i want this password box to allow only four characters when i enter 5th character in password box it will be automatically go to my Home page.like what i write the functionality in login click same functionality will work when i enter 5th character in password box.

    Regards,

    pradeep

    Thursday, February 11, 2016 6:34 AM

Answers

  • Pradeep,

    Create a TextChanged EventHandler in your password textbox and write the below code.

    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
            {
                TextBox textBox = sender as TextBox;
                if (textBox != null)
                {
                    string text = textBox.Text;
                    if (text.Length > 5)
                    {
                        Frame.Navigate(typeof(HomePage));
                    }
                }
            }


    Please mark this answer if this is helpful.
    Thursday, February 11, 2016 9:31 AM