Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lose Textbox Focus

In my Windows Phone 7 Application I've written a bit of code to make the focus jump to the next textbox on the return key bein pressed. This all works fine, but now what I want to do is get the software keyboard out of the way if the user pressed return on the final textbox. However there is no UnFocus() method. What should I do instead? :)

I thought about Focusing something else (e.g. The PhoneApplicationPage) but this doesnt have a Focus() method.

        public List<TextBox> Textboxes = new List<TextBox> { };

    public void CheckForReturn(object sender, KeyEventArgs e)
    {
        TextBox ThisTextbox = sender as TextBox;
        if (e.Key == Key.Enter)
        {
            int ThisTextboxListPosition = Textboxes.IndexOf(ThisTextbox);
            int NextTextboxListPosition = ThisTextboxListPosition + 1;

            if (NextTextboxListPosition < Textboxes.Count)
            {
                TextBox NextTextBox = Textboxes[NextTextboxListPosition];
                NextTextBox.Focus();
            }
            else
            {
                //Something like this!
                //ThisTextbox.Unfocus();
            }
        }
    }
like image 418
dannybrown Avatar asked Dec 12 '22 07:12

dannybrown


1 Answers

I am always use in this situation

this.Focus()
like image 63
Ku6opr Avatar answered Dec 26 '22 13:12

Ku6opr