-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathBindHtmlAttachedBehavior.cs
More file actions
47 lines (41 loc) · 1.68 KB
/
BindHtmlAttachedBehavior.cs
File metadata and controls
47 lines (41 loc) · 1.68 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
39
40
41
42
43
44
45
46
47
using CefSharp.Wpf;
using System.Windows;
using System.Windows.Interactivity;
namespace CefSharp.MinimalExample.Wpf.Binding.Behaviors
{
public class LoadHtmlBehavior : Behavior<ChromiumWebBrowser>
{
// Using a DependencyProperty as the backing store for Html. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HtmlProperty =
DependencyProperty.Register(
"Html",
typeof(string),
typeof(LoadHtmlBehavior),
new PropertyMetadata(string.Empty, OnHtmlChanged));
// Using a DependencyProperty as the backing store for HtmlUrl. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HtmlUrlProperty =
DependencyProperty.Register(
"HtmlUrl",
typeof(string),
typeof(LoadHtmlBehavior),
new PropertyMetadata(string.Empty));
public string Html
{
get { return (string)GetValue(HtmlProperty); }
set { SetValue(HtmlProperty, value); }
}
public string HtmlUrl
{
get { return (string)GetValue(HtmlUrlProperty); }
set { SetValue(HtmlUrlProperty, value); }
}
private static void OnHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue == null || string.IsNullOrWhiteSpace((string)e.NewValue))
{
return;
}
(d as LoadHtmlBehavior)?.AssociatedObject.LoadHtml((string)e.NewValue, "about:blank");
}
}
}