-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathHtmlBindingHelper.cs
More file actions
38 lines (32 loc) · 1.21 KB
/
HtmlBindingHelper.cs
File metadata and controls
38 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using CefSharp.Wpf;
using System.Windows;
namespace CefSharp.MinimalExample.Wpf.Binding.Behaviors
{
public static class HtmlBindingHelper
{
// Using a DependencyProperty as the backing store for Html. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HtmlProperty =
DependencyProperty.RegisterAttached(
"Html",
typeof(string),
typeof(HtmlBindingHelper),
new PropertyMetadata(string.Empty, OnHtmlChanged));
public static string GetHtml(DependencyObject obj)
{
return (string)obj.GetValue(HtmlProperty);
}
public static void SetHtml(DependencyObject obj, string value)
{
obj.SetValue(HtmlProperty, value);
}
private static void OnHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
string htmlText = e.NewValue as string;
if (string.IsNullOrWhiteSpace(htmlText))
{
htmlText = string.Empty;
}
((ChromiumWebBrowser)d).LoadHtml(htmlText, "http://cefsharp/loadHtml");
}
}
}