简体   繁体   中英

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

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.

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;
}        

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);
 }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM