Can the F5 key be disabled in a navigation window in WPF?

3.3k views Asked by At

I have a small application that uses a navigation window and a set of pages. My application is not a browser per se and thus I dont want the user to be able to refresh the page by pressing F5. Is there a way to disable this key in my application? Many thanks all.

2

There are 2 answers

1
Jens On BEST ANSWER

You could disable refreshing altogether, by attaching a handler to the Navigating event:

yourNavigationWindow.Navigating += OnNavigating;

// ...

void OnNavigating(object sender, NavigatingCancelEventArgs e)
{
    if(e.NavigationMode == NavigationMode.Refresh)
        e.Cancel = true;
}        
0
PeterB On

You can try to remove the CommandBinding from the NavigationWindow. NavigationCommand.Refresh

Something like:

CommandBinding removeBinding=null;
foreach(CommandBinding cb in navigationWindow.CommandBindings){
 if(cb.Command==NavigationCommand.Refresh){
   removeBinding=cb;
   break;
 }
 if(removeBinding != null){
   navigationWindow.CommandBindings.Remove(removeBinding);
 }

}