Skip to content
This repository has been archived by the owner on Apr 10, 2020. It is now read-only.

Focusing PhonePasswordBox #19

Closed
dlecina opened this issue Jul 8, 2014 · 1 comment
Closed

Focusing PhonePasswordBox #19

dlecina opened this issue Jul 8, 2014 · 1 comment

Comments

@dlecina
Copy link

dlecina commented Jul 8, 2014

I was trying to use the KeyUp event in a PhoneTextBox to focus the PhonePasswordBox in a typical username-password form, but it just wasn't working. PhonePasswordBox.focus(), at least in this case, does not cause the keyboard to come up and the input box to actually be focused.

In my case, I fixed this with the following extension method:

public static void FocusReal(this PhonePasswordBox pb)
{
    var grid = System.Windows.Media.VisualTreeHelper.GetChild(pb, 0);
    PasswordBox realpb = System.Windows.Media.VisualTreeHelper.GetChild(grid, 2) as PasswordBox;
    realpb.Focus();
}

I was using a modified template (which did not modify the name or type of the actual PasswordBox object), so that is probably the cause of the problem. Also, my solution will not work if the template is changed so that the actual PasswordBox is not in the same position.

Ideally, the focus() code should look for either an object named "PasswordBox" inside the tree, whatever its position, or the first PasswordBox object inside the tree, whatever its name.

@Kinnara Kinnara closed this as completed in dcd3045 Jul 9, 2014
@Kinnara
Copy link
Owner

Kinnara commented Jul 9, 2014

Thanks for the detailed bug report. I just committed a fix. BTW the modified template is not the cause and any template should be fine as long as the "PasswordBox" part is present.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants