简体   繁体   中英

Disable CTRL+P in WPF DocumentViewer

I'm working on a new presentation component for one of our applications. I am building a Custom WPF Control that just has a DocumentViewer in it and hosting that CC in a Windows Forms application with an ElementHost. I'm using Visual Studio 2008 with C#.

I have customized everything through the XAML to give it the look and feel that integrates it perfecting into our application, but one thing remains...

If you press CTRL+P the print dialog still comes up. I'm at a complete loss as to how to disable that function. The use of this CC is to allow the users to pull up and view the Manuals for the systems installed at that site, but we don't want them to accidentally print them (100s of pages).

Add the following code to the DocumentViewer:

    <DocumentViewer.InputBindings>
        <KeyBinding Key="P" Modifiers="Control" Command="ApplicationCommands.NotACommand" />
    </DocumentViewer.InputBindings>

You can always try to consume the keydown event like the following:

private void Window_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.P && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
        {
            e.Handled = true; 
        }
    }

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