如何在设计模式下以编程方式修改web浏览器内容
本文关键字:web 修改 浏览器 方式 编程 设计模式 | 更新日期: 2023-09-27 18:19:02
这是我声明的依赖属性:
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"/>
我想以编程方式修改web浏览器的内容,并禁用键盘修改;我的意思是用一个按钮来进行选择!
我发现如何禁用键盘,而IsDesignMode ="true"
:
<WebBrowser KeyDown="webBrowser1_KeyDown" ... />
后面的代码:
private void webBrowser1_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}
还在寻找我问题第二部分的答案!