Databinding race condition
Posted
by Stephen Price
on Stack Overflow
See other posts from Stack Overflow
or by Stephen Price
Published on 2010-04-14T06:31:20Z
Indexed on
2010/04/14
6:33 UTC
Read the original article
Hit count: 445
silverlight-3.0
|Silverlight
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();
}
}
}
© Stack Overflow or respective owner