的HtmlString屬性不上的WebView(僅這是一個開放的源屬性)存在。但是你可以做的是爲WebView定義一個新的HtmlString附加屬性。只要創建下面的類:
namespace YOURNAMESPACE
{
class MyProperties
{
// "HtmlString" attached property for a WebView
public static readonly DependencyProperty HtmlStringProperty =
DependencyProperty.RegisterAttached("HtmlString", typeof(string), typeof(MyProperties), new PropertyMetadata("", OnHtmlStringChanged));
// Getter and Setter
public static string GetHtmlString(DependencyObject obj) { return (string)obj.GetValue(HtmlStringProperty); }
public static void SetHtmlString(DependencyObject obj, string value) { obj.SetValue(HtmlStringProperty, value); }
// Handler for property changes in the DataContext : set the WebView
private static void OnHtmlStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
WebView wv = d as WebView;
if (wv != null)
{
wv.NavigateToString((string)e.NewValue);
}
}
}
}
假設你的DataContext場被稱爲CurrentHtmlString,那麼你可以使用這個新的WebView HtmlString財產在你的XAML文件綁定其連同語法,如:
<WebView local:MyProperties.HtmlString="{Binding CurrentHtmlString}"></WebView>
通常情況下,你已經有下面一行在你的XAML文件的頂部:
xmlns:local="using:MYNAMESPACE"
你可以在這裏找到更多的解釋羅布·卡普蘭: http://blogs.msdn.com/b/wsdevsol/archive/2013/09/26/binding-html-to-a-webview-with-attached-properties.aspx
[將HTML綁定到帶有附加屬性的WebView](http://blogs.msdn.com/b/wsdevsol/archive/2013/09/26/binding-html-to-a-webview-with-附-properties.aspx) – Bolu