How to handle both the KeyDown and KeyUp events in a Silverlight 3 TextBox
I am attaching handlers to the KeyDown and KeyUp events of a Silverlight 3 TextBox as so:
_masterTextBox.KeyDown += (s, args) =>
{
CheckForUserEnteredText(MasterTextBox.Text);
args.Handled = false;
};
_masterTextBox.KeyUp += (s, args) => { UpdateText(MasterText开发者_如何转开发Box.Text); };
When I comment out the KeyDown handler, then the KeyUp will trap the event, otherwise, only the KeyDown handler is triggered.
Can someone explain why the KeyUp event handler is not firing after the KeyDown handler does?
Thanks.
I think you need to look inside your CheckForUserEnteredText
function. Certainly there is no reason from the posted code alone for KeyUp not to fire and it does in my testing.
Perhaps CheckForUserEnteredText
does something to prevent it? You seem to have both a public field/property called MasterTextBox
and one called _masterTextBox
, do you need both? Could it be the KeyUp is firing but UpdateText isn't doing what you expect? The list could go on, the bottom line is there isn't a problem with the code you've posted.
It turns out that the problem was that I was setting a break point in the keydown method. Apparently, when you set a break point, it misses the keyup event.
精彩评论