相关疑难解决方法(0)

如何在WPF WebBrowser中使用"后退"和"前进"导航按钮事件?

WebBrowserWPF中的控件继承自UIElement,但我们无法在UIElement事件中注册事件处理程序.为什么?在WPF WebBrowser鼠标事件没有按预期工作,它得到了回答,但我仍然无法理解.

无论如何,将处理程序连接到WebBrowser可以捕获大多数鼠标事件的文档提供的事件但不能使用"后退"和"前进"导航按钮事件.由于互联网浏览器可以做到这一点,我认为这是可能的.有什么方法可以解决这个问题吗?

更新: 在这个问题中,'Back' & 'Forward' navigation buttons5键鼠标系统中的XButton1和XButton2.

更新2:我用Navid Rahmani的答案解决了这个问题.我认为有人会需要这个答案,所以我附上了主要部分.如果发现任何问题或更合理的解决方案,请告诉我.

    //This code assumes the `WebBrowser` field named _webBrowser is already initiated.
    //For the detail out of this code, please refer to the Navid Rahmani's answer.

    private bool _isMouseOver;
    private HTMLDocumentEvents2_Event _docEvent;    

    public ctor()
    {
        _webBrowser.LoadCompleted += _webBrowser_LoadCompleted;
    }

    private void _webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
    {
        if (_docEvent != null)
        {
            _docEvent.onmouseover -= _docEvent_onmouseover;
            _docEvent.onmouseout -= _docEvent_onmouseout;
        } …
Run Code Online (Sandbox Code Playgroud)

c# wpf webbrowser-control

8
推荐指数
1
解决办法
5689
查看次数

标签 统计

c# ×1

webbrowser-control ×1

wpf ×1