views:

9

answers:

0

I have a login form (using ChildWindow) and have implemented a Keyup event handler on the passwordbox. If the key is enter then it sets the ChildWindow ResultDialog to true. What seems to be happening is the databinding on the Passwordbox is not happening before the childwindow is closed so the Password property on my Login control is null.

I've tried using KeyUp and Keydown, as well as using a buttonAutoPeer to invoke a click on the Ok button. I've also tried setting the focus to the OKbutton before setting the DialogResult (which closes the window).

private void PasswordBox_KeyUp(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        if (UsernameBox.Text != userPrompt && !string.IsNullOrEmpty(PasswordBox.Password.Trim()))
        {
            this.DialogResult = true;
        }
        else
        {
            UsernameBox.Focus();
        }
    }
}