1

我使用页面和 NavigationWindow:

navigationWindow = new NavigationWindow();
            navigationWindow.Height = 200;
            navigationWindow.Width = 100;
            navigationWindow.WindowState = WindowState.Maximized;
            page = new IntroPage();
            navigationWindow.Navigate(page);
            navigationWindow.Show();

我使用 GoBack 和 GoForward 方法导航,但我不想通过快捷方式(鼠标中的功能按钮等)使用它们。如何禁用这些快捷方式?

4

1 回答 1

0

在您的导航窗口 XAML 中,您可以添加以下内容:

<NavigationWindow.InputBindings>
    <KeyBinding Key="Back" Command="NotACommand" />
    <KeyBinding Key="Next" Command="NotACommand" />
    <KeyBinding Key="BrowserBack" Command="NotACommand" />
    <KeyBinding Key="BrowserForward" Command="NotACommand" />
    <KeyBinding Key="Left" Modifiers="Alt" Command="NotACommand" />
    <KeyBinding Key="Right" Modifiers="Alt" Command="NotACommand" />
</NavigationWindow.InputBindings>

在代码中你可以这样做:

navigationWindow.InputBindings.Add(new KeyBinding(ApplicationCommands.NotACommand, Key.Back, ModifierKeys.None));
navigationWindow.InputBindings.Add(new KeyBinding(ApplicationCommands.NotACommand, Key.Next, ModifierKeys.None));
navigationWindow.InputBindings.Add(new KeyBinding(ApplicationCommands.NotACommand, Key.BrowserBack, ModifierKeys.None));
navigationWindow.InputBindings.Add(new KeyBinding(ApplicationCommands.NotACommand, Key.BrowserForward, ModifierKeys.None));
navigationWindow.InputBindings.Add(new KeyBinding(ApplicationCommands.NotACommand, Key.Left, ModifierKeys.Alt));
navigationWindow.InputBindings.Add(new KeyBinding(ApplicationCommands.NotACommand, Key.Right, ModifierKeys.Alt));

还有其他可以阻止的键,例如 BrowserHome 和 BrowserRefresh 。

如果正在显示导航 UI,这可以防止热键,而不是鼠标导航。如果您只想以编程方式控制导航,则应使用ShowsNavigationUI="False"XAML(作为 NavigationWindow 标记的参数)或mainWindow.ShowsNavigationUI = false;代码隐藏导航 UI。

此外,您可以像我在上面对 KeyBindings 所做的那样防止 MouseBindings,添加带有 MouseAction 属性集的新 MouseBinding 对象。

于 2014-07-04T14:14:14.003 回答