Is it possible to catch F5 in a Silverlight application
I have a feature request to catch the 开发者_如何学GoF5 key and refresh content within a Silverlight application instead of having the browser refresh the entire application. In a simple app, I tried hooking the KeyDown event and it never gets there with F5.
Is this something that is possible to do in Silverlight?
The browser gets all key pressed first and determines whether it will pass them to the hosted content (Silverlight) or not. AFAIK there is no way of stopping a refresh when F5 is pressed, since it will always be handled by the browser.
You may be able to use javascript to detect the keypress and pass it to SL, but I'm pretty sure that won't stop the browser from refreshing.
I found this post that shows how to do it in javascript. I tested it and it works (IE9)... unless you have the focus in the Silverlight application :-). This SO post is similar, but doesn't have a solution yet either.
After trying that out, I agree with @Phil, that stopping the refresh probably isn't possible, at least for IE.
If the client is happy to let your code to that to their browser then perhaps you can persuade them to install the app out-of-browser where you can have much greater navigational control
精彩评论