Skip to content

Instantly share code, notes, and snippets.

@kharasoft
Created July 29, 2012 02:55
Show Gist options
  • Save kharasoft/3195861 to your computer and use it in GitHub Desktop.
Save kharasoft/3195861 to your computer and use it in GitHub Desktop.
Attached Property to set the HTML Source of a WebView control
public class WebClientHelper : DependencyObject
{
public static readonly DependencyProperty HtmlProperty =
DependencyProperty.RegisterAttached("Html", typeof(string), typeof(WebClientHelper), new PropertyMetadata(null, HtmlChanged));
public static void SetHtml(DependencyObject obj, string value)
{
obj.SetValue(HtmlProperty, value);
}
public static string GetHtml(DependencyObject obj)
{
return (string)obj.GetValue(HtmlProperty);
}
private static void HtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var webView = d as WebView;
if (webView == null)
return;
webView.NavigateToString((string)e.NewValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment