<WebBrowser x:Name="messageBufferWebBrowser"
controls:WebBrowserUtility.Body="{Binding MessageBuilder}"/>
我使用此类来启用与 WebBrowser 控件主体的绑定
public static class WebBrowserUtility
{
public static readonly DependencyProperty BodyProperty =
DependencyProperty.RegisterAttached("Body", typeof(string), typeof(WebBrowserUtility), new PropertyMetadata(OnBodyChanged));
public static string GetBody(DependencyObject dependencyObject)
{
return (string)dependencyObject.GetValue(BodyProperty);
}
public static void SetBody(DependencyObject dependencyObject, string body)
{
dependencyObject.SetValue(BodyProperty, body);
}
private static void OnBodyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var webBrowser = d as WebBrowser;
if (!string.IsNullOrWhiteSpace(e.NewValue as string) && webBrowser != null)
{
if (Application.Current.MainWindow != null && !DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow))
{
webBrowser.NavigateToString((string)e.NewValue);
}
}
}
}
这是我的 WebBrowser,我将其绑定到 ViewModel 上的 StringBuilder 属性。如何让 WebBrowser 控件滚动到末尾?
如果将 WebBrowser 的 Document 属性转换为 mshtml.HTMLDocument,则可以滚动到页面中的特定位置(或使用可能的最大值滚动到底部):
var html = webBrowser.Document as mshtml.HTMLDocument;
html.parentWindow.scroll(0, 10000000);
请注意,您必须添加对Microsoft.mshtml
在你的项目中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)