Question

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).

Was it helpful?

Solution

Add the following code to the DocumentViewer:

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

OTHER TIPS

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; 
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top