简体   繁体   English

防止 WPF 捕获 F5 以便我可以将其用于我自己的目的?

[英]Prevent WPF from catching F5 so that i can use it for my own purposes?

I want a refresh hotkey for my application, the standard key for "refresh" is F5 for most programs.我想要我的应用程序的刷新热键,大多数程序的“刷新”标准键是 F5。 So i would like to use that hotkey for my program aswell.所以我也想为我的程序使用该热键。 The problem is that WPF uses F5 to refresh Frames.问题是 WPF 使用 F5 刷新 Frames。

I managed to turn off refresh on Frames with this in the codebehind for the usercontrol with the frame:我设法在带有框架的用户控件的代码隐藏中使用此关闭框架刷新:

    private void pageFrame_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
    {
        if (e.NavigationMode == NavigationMode.Refresh)
        {
            e.Cancel = true;
        }
    }

However, this still "catches" the keypress so that i cannot detect it else where in the program.但是,这仍然会“捕获”按键,因此我无法在程序的其他地方检测到它。 It nullifies the key press as though it never happened.它使按键无效,就好像它从未发生过一样。 How can i stop Frame from refreshing when i press F5 and at the same time use F5 in other places?如何在按 F5 时阻止 Frame 刷新,同时在其他地方使用 F5?

I detect keypresses with:我通过以下方式检测按键:

    public static void KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    {
        switch (e.Key)
        {
            case Key.F6: //Send Group
                //THIS HERE WORKS!
                break;
            case Key.F5: //Refresh Group
                //THIS HERE DOES NOT WORK!
            break;
        }
    }

This function is subscribed to the main window's "KeyDown" event.这个 function 订阅了主窗口的“KeyDown”事件。

For anyone finding this page with the same problem.对于发现此页面有相同问题的任何人。 I fixed it by using ContentControl instead of Frame and UserControl instead of Page .我通过使用ContentControl而不是FrameUserControl而不是Page来修复它。

I just used Frame and Page because of their names so i figured that was what you are supposed to do.我只是因为它们的名字而使用了 Frame 和 Page,所以我认为这就是你应该做的。 But using ContentControl and UserControl instead gives you more freedom and there is nothing Frame/Page can do that ContentControl/UserControl cant be programmed to do.但是使用 ContentControl 和 UserControl 可以给您更多的自由,并且没有什么 Frame/Page 可以做的,ContentControl/UserControl 不能通过编程来做。

https://social.tec.net.microsoft.com/wiki/contents/articles/52485.wpf-tips-and-tricks-using-contentcontrol-instead-of-frame-and-page-for-navigation.aspx https://social.tec.net.microsoft.com/wiki/contents/articles/52485.wpf-tips-and-tricks-using-contentcontrol-instead-of-frame-and-page-for-navigation.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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