我正在搜索如何在 webview 中绑定 html,我发现了这个:
public static class WebBrowserHelper
{
public static readonly DependencyProperty HtmlProperty = DependencyProperty.RegisterAttached(
"Html", typeof(string), typeof(WebBrowserHelper), new PropertyMetadata(null, OnHtmlChanged));
public static string GetHtml(DependencyObject dependencyObject)
{
return (string)dependencyObject.GetValue(HtmlProperty);
}
public static void SetHtml(DependencyObject dependencyObject, string value)
{
dependencyObject.SetValue(HtmlProperty, value);
}
private static void OnHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var browser = d as WebView;
if(browser == null)
return;
var html = e.NewValue.ToString();
browser.NavigateToString(html);
}
}
xamls 代码应该是这样的
<WebView Grid.Column="1" Height="628" Margin="10,0" VerticalAlignment="Top" cxi:WebBrowserHelper.Html="{Binding Question.Body}" />
但我无法在 xaml 中访问此属性,我做错了吗?