How to: Handle or Simulate User Input with the WPF WebControl
The WPF WebControl uses WPF specific presenters (IWebViewPresenter), depending on the specified ViewType. Presenters are used in the visual tree when styling a WPF WebControl. These can be custom WPF surfaces also implementing ISurface (for offscreen views) or any other control providing custom presentation of an IWebView instance.
When WebControl.ViewType is set to Offscreen (default), the predefined WebViewPresenter is used for presentation. This is an ISurface component that uses 100% WPF logic to copy the view’s pixel buffer to a bitmap that it then renders for presentation.
WebViewPresenter inherits FrameworkElement and is part of the WPF WebControl’s default style. When the visual tree is loaded for presentation, the WPF WebControl uses the IWebViewPresenter interface to communicate with the WebViewPresenter that takes care of all UI related operations which besides rendering include:
Handling user input
Presentation of dialogs
Presentation of menus
When using the WPF WebControl, it is the WebViewPresenter and not the WebControl itself that handles user input. This means that handling user input related events on the WebControl, will not prevent the WebViewPresenter from handling these events and passing them to the native view.
Since the WebViewPresenter is part of the WebControl’s visual tree, the appropriate way to handle such events yourself, is by handling the Preview events.
Native windowed views handle user input themselves and there’s no way to handle or simulate user input on the managed side. If you need to handle or simulate user input, make sure that WebControl.ViewType is set to Offscreen (default).
The following example demonstrates:
How to prevent the presenter from handling the TAB and Space characters and passing them to the native view.