The WebBrowser
control in WPF is inherited from theUIElement
, but we cannot register event handlers in UIElement
events. Why is it? At
Much simpler way....
This works for me in WPF and .net 4.5
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton.Equals(MouseButton.XButton1)) MessageBox.Show(@"back");
if (e.ChangedButton.Equals(MouseButton.XButton2)) MessageBox.Show(@"forward");
}
The WebBrowser controll is really just thin wrapper around the Trident COM object. It's not 'pure WPF' like other built-in controls... so lots of normal things don't work with it. To answer your question, the closest you can get is hooking into the Navigating event. This won't tell you whether the user is trying to go forwards or back or elsewhere but it will give you the URL and the opportunity to set e.Cancel = true to stop the navigation (usually followed by calling Navigate(url) to take the user somewhere else).
You can use low level hook of mouse and check if the xbutton1 or xbutton2 clicked
look here
for the value of WM_XBUTTONDOWN
look http://msdn.microsoft.com/en-us/library/ms646245(VS.85).aspx