Skip to main content
Home Forums Silverlight Programming Programming with .NET - General KeyDown event throws an exception when MessageBox.Show(e.Key.ToString()) is called
3 replies. Latest Post by Jonathan Shen – MSFT on June 11, 2009.
(0)
Grey Matter
Member
39 points
106 Posts
06-06-2009 6:43 PM |
The TextBox's event:
private void TextBox_KeyDown(object sender, KeyEventArgs e){ MessageBox.Show(e.Key.ToString());}
throws an exception on any key pressed just except the first one.
It doesn't happen at all on the KeyUp event with the same code within.
What does it mean?
varshavmane
Contributor
6263 points
1,489 Posts
06-07-2009 8:30 AM |
Check this link:
http://blogs.vertigo.com/personal/keithc/Blog/archive/2008/12/02/keydown-and-messagebox-dont-mix-well-in-silverlight.aspx
Its will answer your post. Hope it helps you
06-07-2009 7:31 PM |
Thank for your explanation, but I still have some doubts:
If any other thread (event) tries to display MessageBox at the same time why can't I catch it at my breakpoint?
It's caught only once and sometimes drops on it. By the way, my Firefox drops too.
Then I added a TextBlock to check a chance of multiple KeyDown events and was putting every got key to the TextBlock's content.
But no multiple events occurred.
Jonathan...
All-Star
23562 points
2,304 Posts
06-11-2009 6:46 AM |
Hi Grey Matter,
This is a known issue and has been fixed in Silverlight 3. Currently, the workaround is to do it like this.
private void myTextBox_KeyDown(object sender, KeyEventArgs e) { Dispatcher.BeginInvoke(()=>{ MessageBox.Show(e.Key.ToString()); }); }
Best regards,
Jonathan