0

这是我声明的依赖属性:

public static void IsDesignModePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            WebBrowser browser = obj as WebBrowser;
            if (browser != null)
            {
                Boolean designMode = (Boolean)args.NewValue;
                if (designMode)
                {
                    browser.LoadCompleted += (s, e) =>
                    {
                        var htmlDoc = (s as WebBrowser).Document as IHTMLDocument2;
                        htmlDoc.body.setAttribute("contenteditable", "true");
                        htmlDoc.designMode = "On";
                    };
                }
                else
                {
                    browser.LoadCompleted += (s, e) =>
                    {
                        var htmlDoc = (s as WebBrowser).Document as IHTMLDocument2;
                        htmlDoc.body.setAttribute("contenteditable", "false");
                        htmlDoc.designMode = "Off";
                    };
                }
            }
        }

这是我的网络浏览器控件:

<WebBrowser  viewmodel:BrowserBehavior.IsDesignMode="True"  x:Name="webBrowser1" viewmodel:BrowserBehavior.Html="{Binding SelectedNode.ContentData.FileName, Converter={StaticResource converter}, Mode=OneWay}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="612"/>

我想以编程方式修改网络浏览器的内容,并禁用键盘修改;我的意思是有一个按钮,作用于选择!

这怎么可能?

4

1 回答 1

0

我发现了如何在以下情况下禁用键盘IsDesignMode ="true"

<WebBrowser KeyDown="webBrowser1_KeyDown" ... />

在后面的代码中:

private void webBrowser1_KeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = true;
        }

仍在寻找我问题第二部分的答案!

于 2014-08-22T11:25:29.580 回答