forked from AvaloniaUI/Avalonia.HtmlRenderer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HtmlControl.cs
615 lines (541 loc) · 24.9 KB
/
HtmlControl.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"
using System;
using Avalonia.Controls.Primitives;
using Avalonia.HtmlRenderer;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Threading;
using Avalonia.VisualTree;
using TheArtOfDev.HtmlRenderer.Core;
using TheArtOfDev.HtmlRenderer.Core.Entities;
using TheArtOfDev.HtmlRenderer.Avalonia;
using TheArtOfDev.HtmlRenderer.Avalonia.Adapters;
namespace Avalonia.Controls.Html
{
/// <summary>
/// Provides HTML rendering using the text property.<br/>
/// Avalonia control that will render html content in it's client rectangle.<br/>
/// The control will handle mouse and keyboard events on it to support html text selection, copy-paste and mouse clicks.<br/>
/// <para>
/// The major differential to use HtmlPanel or HtmlLabel is size and scrollbars.<br/>
/// If the size of the control depends on the html content the HtmlLabel should be used.<br/>
/// If the size is set by some kind of layout then HtmlPanel is more suitable, also shows scrollbars if the html contents is larger than the control client rectangle.<br/>
/// </para>
/// <para>
/// <h4>LinkClicked event:</h4>
/// Raised when the user clicks on a link in the html.<br/>
/// Allows canceling the execution of the link.
/// </para>
/// <para>
/// <h4>StylesheetLoad event:</h4>
/// Raised when a stylesheet is about to be loaded by file path or URI by link element.<br/>
/// This event allows to provide the stylesheet manually or provide new source (file or uri) to load from.<br/>
/// If no alternative data is provided the original source will be used.<br/>
/// </para>
/// <para>
/// <h4>ImageLoad event:</h4>
/// Raised when an image is about to be loaded by file path or URI.<br/>
/// This event allows to provide the image manually, if not handled the image will be loaded from file or download from URI.
/// </para>
/// <para>
/// <h4>RenderError event:</h4>
/// Raised when an error occurred during html rendering.<br/>
/// </para>
/// </summary>
public class HtmlControl : Control
{
/// <summary>
/// Underline html container instance.
/// </summary>
protected readonly HtmlContainer _htmlContainer;
/// <summary>
/// the base stylesheet data used in the control
/// </summary>
protected CssData _baseCssData;
/// <summary>
/// The last position of the scrollbars to know if it has changed to update mouse
/// </summary>
protected Point _lastScrollOffset;
public static readonly AvaloniaProperty AvoidImagesLateLoadingProperty =
PropertyHelper.Register<HtmlControl, bool>(nameof(AvoidImagesLateLoading), false, OnAvaloniaProperty_valueChanged);
public static readonly AvaloniaProperty IsSelectionEnabledProperty =
PropertyHelper.Register<HtmlControl, bool>(nameof(IsSelectionEnabled), true, OnAvaloniaProperty_valueChanged);
public static readonly AvaloniaProperty IsContextMenuEnabledProperty =
PropertyHelper.Register<HtmlControl, bool>(nameof(IsContextMenuEnabled), true, OnAvaloniaProperty_valueChanged);
public static readonly AvaloniaProperty BaseStylesheetProperty =
PropertyHelper.Register<HtmlControl, string>(nameof(BaseStylesheet), null, OnAvaloniaProperty_valueChanged);
public static readonly AvaloniaProperty TextProperty =
PropertyHelper.Register<HtmlControl, string>(nameof(Text), null, OnAvaloniaProperty_valueChanged);
public static readonly StyledProperty<IBrush> BackgroundProperty =
Border.BackgroundProperty.AddOwner<HtmlControl>();
public static readonly AvaloniaProperty BorderThicknessProperty =
AvaloniaProperty.Register<HtmlControl, Thickness>(nameof(BorderThickness), new Thickness(0));
public static readonly AvaloniaProperty BorderBrushProperty =
AvaloniaProperty.Register<HtmlControl, IBrush>(nameof(BorderBrush));
public static readonly AvaloniaProperty PaddingProperty =
AvaloniaProperty.Register<HtmlControl, Thickness>(nameof(Padding), new Thickness(0));
public static readonly RoutedEvent LoadCompleteEvent =
RoutedEvent.Register<RoutedEventArgs>("LoadComplete", RoutingStrategies.Bubble, typeof(HtmlControl));
public static readonly RoutedEvent LinkClickedEvent =
RoutedEvent.Register<HtmlRendererRoutedEventArgs<HtmlLinkClickedEventArgs>>("LinkClicked", RoutingStrategies.Bubble, typeof(HtmlControl));
public static readonly RoutedEvent RenderErrorEvent
= RoutedEvent.Register<HtmlRendererRoutedEventArgs<HtmlRenderErrorEventArgs>>("RenderError", RoutingStrategies.Bubble, typeof(HtmlControl));
public static readonly RoutedEvent RefreshEvent
= RoutedEvent.Register<HtmlRendererRoutedEventArgs<HtmlRefreshEventArgs>>("Refresh", RoutingStrategies.Bubble, typeof(HtmlControl));
public static readonly RoutedEvent StylesheetLoadEvent
= RoutedEvent.Register<HtmlRendererRoutedEventArgs<HtmlStylesheetLoadEventArgs>>("StylesheetLoad", RoutingStrategies.Bubble, typeof(HtmlControl));
public static readonly RoutedEvent ImageLoadEvent
= RoutedEvent.Register<HtmlRendererRoutedEventArgs<HtmlImageLoadEventArgs>>("ImageLoad", RoutingStrategies.Bubble,
typeof (HtmlControl));
static HtmlControl()
{
FocusableProperty.OverrideDefaultValue(typeof(HtmlControl), true);
AffectsRender(TextProperty);
}
/// <summary>
/// Creates a new HtmlPanel and sets a basic css for it's styling.
/// </summary>
protected HtmlControl()
{
_htmlContainer = new HtmlContainer();
_htmlContainer.LoadComplete += OnLoadComplete;
_htmlContainer.LinkClicked += OnLinkClicked;
_htmlContainer.RenderError += OnRenderError;
_htmlContainer.Refresh += OnRefresh;
_htmlContainer.StylesheetLoad += OnStylesheetLoad;
_htmlContainer.ImageLoad += OnImageLoad;
}
//Hack for adapter
internal bool LeftMouseButton { get; private set; }
/// <summary>
/// Raised when the set html document has been fully loaded.<br/>
/// Allows manipulation of the html dom, scroll position, etc.
/// </summary>
public event EventHandler<HtmlRendererRoutedEventArgs<EventArgs>> LoadComplete
{
add { AddHandler(LoadCompleteEvent, value); }
remove { RemoveHandler(LoadCompleteEvent, value); }
}
/// <summary>
/// Raised when the user clicks on a link in the html.<br/>
/// Allows canceling the execution of the link.
/// </summary>
public event EventHandler<HtmlRendererRoutedEventArgs<HtmlLinkClickedEventArgs>> LinkClicked
{
add { AddHandler(LinkClickedEvent, value); }
remove { RemoveHandler(LinkClickedEvent, value); }
}
/// <summary>
/// Raised when an error occurred during html rendering.<br/>
/// </summary>
public event EventHandler<HtmlRendererRoutedEventArgs<HtmlRenderErrorEventArgs>> RenderError
{
add { AddHandler(RenderErrorEvent, value); }
remove { RemoveHandler(RenderErrorEvent, value); }
}
/// <summary>
/// Raised when a stylesheet is about to be loaded by file path or URI by link element.<br/>
/// This event allows to provide the stylesheet manually or provide new source (file or uri) to load from.<br/>
/// If no alternative data is provided the original source will be used.<br/>
/// </summary>
public event EventHandler<HtmlRendererRoutedEventArgs<HtmlStylesheetLoadEventArgs>> StylesheetLoad
{
add { AddHandler(StylesheetLoadEvent, value); }
remove { RemoveHandler(StylesheetLoadEvent, value); }
}
/// <summary>
/// Raised when an image is about to be loaded by file path or URI.<br/>
/// This event allows to provide the image manually, if not handled the image will be loaded from file or download from URI.
/// </summary>
public event EventHandler<HtmlRendererRoutedEventArgs<HtmlImageLoadEventArgs>> ImageLoad
{
add { AddHandler(ImageLoadEvent, value); }
remove { RemoveHandler(ImageLoadEvent, value); }
}
/// <summary>
/// Gets or sets a value indicating if image loading only when visible should be avoided (default - false).<br/>
/// True - images are loaded as soon as the html is parsed.<br/>
/// False - images that are not visible because of scroll location are not loaded until they are scrolled to.
/// </summary>
/// <remarks>
/// Images late loading improve performance if the page contains image outside the visible scroll area, especially if there is large
/// amount of images, as all image loading is delayed (downloading and loading into memory).<br/>
/// Late image loading may effect the layout and actual size as image without set size will not have actual size until they are loaded
/// resulting in layout change during user scroll.<br/>
/// Early image loading may also effect the layout if image without known size above the current scroll location are loaded as they
/// will push the html elements down.
/// </remarks>
[Category("Behavior")]
[Description("If image loading only when visible should be avoided")]
public bool AvoidImagesLateLoading
{
get { return (bool)GetValue(AvoidImagesLateLoadingProperty); }
set { SetValue(AvoidImagesLateLoadingProperty, value); }
}
/// <summary>
/// Is content selection is enabled for the rendered html (default - true).<br/>
/// If set to 'false' the rendered html will be static only with ability to click on links.
/// </summary>
[Category("Behavior")]
[Description("Is content selection is enabled for the rendered html.")]
public bool IsSelectionEnabled
{
get { return (bool)GetValue(IsSelectionEnabledProperty); }
set { SetValue(IsSelectionEnabledProperty, value); }
}
/// <summary>
/// Is the build-in context menu enabled and will be shown on mouse right click (default - true)
/// </summary>
[Category("Behavior")]
[Description("Is the build-in context menu enabled and will be shown on mouse right click.")]
public bool IsContextMenuEnabled
{
get { return (bool)GetValue(IsContextMenuEnabledProperty); }
set { SetValue(IsContextMenuEnabledProperty, value); }
}
/// <summary>
/// Set base stylesheet to be used by html rendered in the panel.
/// </summary>
[Category("Appearance")]
[Description("Set base stylesheet to be used by html rendered in the control.")]
public string BaseStylesheet
{
get { return (string)GetValue(BaseStylesheetProperty); }
set { SetValue(BaseStylesheetProperty, value); }
}
/// <summary>
/// Gets or sets the text of this panel
/// </summary>
[Description("Sets the html of this control.")]
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public Thickness BorderThickness
{
get { return (Thickness) GetValue(BorderThicknessProperty); }
set { SetValue(BorderThicknessProperty, value); }
}
public IBrush BorderBrush
{
get { return (IBrush)GetValue(BorderBrushProperty); }
set { SetValue(BorderThicknessProperty, value); }
}
public Thickness Padding
{
get { return (Thickness)GetValue(PaddingProperty); }
set { SetValue(PaddingProperty, value); }
}
public IBrush Background
{
get { return (IBrush) GetValue(BackgroundProperty); }
set { SetValue(BackgroundProperty, value);}
}
/// <summary>
/// Get the currently selected text segment in the html.
/// </summary>
[Browsable(false)]
public virtual string SelectedText
{
get { return _htmlContainer.SelectedText; }
}
/// <summary>
/// Copy the currently selected html segment with style.
/// </summary>
[Browsable(false)]
public virtual string SelectedHtml
{
get { return _htmlContainer.SelectedHtml; }
}
/// <summary>
/// Get html from the current DOM tree with inline style.
/// </summary>
/// <returns>generated html</returns>
public virtual string GetHtml()
{
return _htmlContainer != null ? _htmlContainer.GetHtml() : null;
}
/// <summary>
/// Get the rectangle of html element as calculated by html layout.<br/>
/// Element if found by id (id attribute on the html element).<br/>
/// Note: to get the screen rectangle you need to adjust by the hosting control.<br/>
/// </summary>
/// <param name="elementId">the id of the element to get its rectangle</param>
/// <returns>the rectangle of the element or null if not found</returns>
public virtual Rect? GetElementRectangle(string elementId)
{
return _htmlContainer != null ? _htmlContainer.GetElementRectangle(elementId) : null;
}
/// <summary>
/// Clear the current selection.
/// </summary>
public void ClearSelection()
{
if (_htmlContainer != null)
_htmlContainer.ClearSelection();
}
//HACK: We don't have support for RenderSize for now
private Size RenderSize => new Size(Bounds.Width, Bounds.Height);
public override void Render(DrawingContext context)
{
context.FillRectangle(Background, new Rect(RenderSize));
if (BorderThickness != new Thickness(0) && BorderBrush != null)
{
var brush = new SolidColorBrush(Colors.Black);
if (BorderThickness.Top > 0)
context.FillRectangle(brush, new Rect(0, 0, RenderSize.Width, BorderThickness.Top));
if (BorderThickness.Bottom > 0)
context.FillRectangle(brush, new Rect(0, RenderSize.Height - BorderThickness.Bottom, RenderSize.Width, BorderThickness.Bottom));
if (BorderThickness.Left > 0)
context.FillRectangle(brush, new Rect(0, 0, BorderThickness.Left, RenderSize.Height));
if (BorderThickness.Right > 0)
context.FillRectangle(brush, new Rect(RenderSize.Width - BorderThickness.Right, 0, BorderThickness.Right, RenderSize.Height));
}
var htmlWidth = HtmlWidth(RenderSize);
var htmlHeight = HtmlHeight(RenderSize);
if (_htmlContainer != null && htmlWidth > 0 && htmlHeight > 0)
{
/*
//TODO: Revert antialiasing fixes
var windows = Window.GetWindow(this);
if (windows != null)
{
// adjust render location to round point so we won't get anti-alias smugness
var wPoint = TranslatePoint(new Point(0, 0), windows);
wPoint.Offset(-(int)wPoint.X, -(int)wPoint.Y);
var xTrans = wPoint.X < .5 ? -wPoint.X : 1 - wPoint.X;
var yTrans = wPoint.Y < .5 ? -wPoint.Y : 1 - wPoint.Y;
context.PushTransform(new TranslateTransform(xTrans, yTrans));
}*/
using (context.PushClip(new Rect(Padding.Left + BorderThickness.Left, Padding.Top + BorderThickness.Top,
htmlWidth, (int) htmlHeight)))
{
_htmlContainer.Location = new Point(Padding.Left + BorderThickness.Left,
Padding.Top + BorderThickness.Top);
_htmlContainer.PerformPaint(context,
new Rect(Padding.Left + BorderThickness.Left, Padding.Top + BorderThickness.Top, htmlWidth,
htmlHeight));
}
if (!_lastScrollOffset.Equals(_htmlContainer.ScrollOffset))
{
_lastScrollOffset = _htmlContainer.ScrollOffset;
InvokeMouseMove();
}
}
}
/// <summary>
/// Handle mouse move to handle hover cursor and text selection.
/// </summary>
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
if (_htmlContainer != null)
_htmlContainer.HandleMouseMove(this, e.GetPosition(this));
}
/// <summary>
/// Handle mouse leave to handle cursor change.
/// </summary>
protected override void OnPointerLeave(PointerEventArgs e)
{
base.OnPointerLeave(e);
if (_htmlContainer != null)
_htmlContainer.HandleMouseLeave(this);
}
/// <summary>
/// Handle mouse down to handle selection.
/// </summary>
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
LeftMouseButton = true;
_htmlContainer?.HandleLeftMouseDown(this, e);
}
/// <summary>
/// Handle mouse up to handle selection and link click.
/// </summary>
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
base.OnPointerReleased(e);
LeftMouseButton = false;
if (_htmlContainer != null)
_htmlContainer.HandleLeftMouseUp(this, e);
}
//TODO: Implement double click
/*
/// <summary>
/// Handle mouse double click to select word under the mouse.
/// </summary>
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(e);
if (_htmlContainer != null)
_htmlContainer.HandleMouseDoubleClick(this, e);
}
*/
/// <summary>
/// Handle key down event for selection, copy and scrollbars handling.
/// </summary>
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (_htmlContainer != null)
_htmlContainer.HandleKeyDown(this, e);
}
void RaiseRouted<T>(RoutedEvent ev, T arg)
{
var e =new HtmlRendererRoutedEventArgs<T>
{
Event = arg,
Source = this,
RoutedEvent = ev,
Route = ev.RoutingStrategies
};
RaiseEvent(e);
}
/// <summary>
/// Propagate the LoadComplete event from root container.
/// </summary>
protected virtual void OnLoadComplete(EventArgs e) => RaiseRouted(LoadCompleteEvent, e);
/// <summary>
/// Propagate the LinkClicked event from root container.
/// </summary>
protected virtual void OnLinkClicked(HtmlLinkClickedEventArgs e) => RaiseRouted(LinkClickedEvent, e);
/// <summary>
/// Propagate the Render Error event from root container.
/// </summary>
protected virtual void OnRenderError(HtmlRenderErrorEventArgs e) => RaiseRouted(RenderErrorEvent, e);
/// <summary>
/// Propagate the stylesheet load event from root container.
/// </summary>
protected virtual void OnStylesheetLoad(HtmlStylesheetLoadEventArgs e) => RaiseRouted(StylesheetLoadEvent, e);
/// <summary>
/// Propagate the image load event from root container.
/// </summary>
protected virtual void OnImageLoad(HtmlImageLoadEventArgs e) => RaiseRouted(ImageLoadEvent, e);
/// <summary>
/// Handle html renderer invalidate and re-layout as requested.
/// </summary>
protected virtual void OnRefresh(HtmlRefreshEventArgs e)
{
if (e.Layout)
InvalidateMeasure();
InvalidateVisual();
}
/// <summary>
/// Get the width the HTML has to render in (not including vertical scroll iff it is visible)
/// </summary>
protected virtual double HtmlWidth(Size size)
{
return size.Width - Padding.Left - Padding.Right - BorderThickness.Left - BorderThickness.Right;
}
/// <summary>
/// Get the width the HTML has to render in (not including vertical scroll iff it is visible)
/// </summary>
protected virtual double HtmlHeight(Size size)
{
return size.Height - Padding.Top - Padding.Bottom - BorderThickness.Top - BorderThickness.Bottom;
}
/// <summary>
/// call mouse move to handle paint after scroll or html change affecting mouse cursor.
/// </summary>
protected virtual void InvokeMouseMove()
{
_htmlContainer.HandleMouseMove(this, (this.GetVisualRoot() as IInputRoot)?.MouseDevice?.GetPosition(this) ?? default(Point));
}
/// <summary>
/// Handle when dependency property value changes to update the underline HtmlContainer with the new value.
/// </summary>
private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject,
AvaloniaPropertyChangedEventArgs e)
{
var control = AvaloniaObject as HtmlControl;
if (control != null)
{
var htmlContainer = control._htmlContainer;
if (e.Property == AvoidImagesLateLoadingProperty)
{
htmlContainer.AvoidImagesLateLoading = (bool) e.NewValue;
}
else if (e.Property == IsSelectionEnabledProperty)
{
htmlContainer.IsSelectionEnabled = (bool) e.NewValue;
}
else if (e.Property == IsContextMenuEnabledProperty)
{
htmlContainer.IsContextMenuEnabled = (bool) e.NewValue;
}
else if (e.Property == BaseStylesheetProperty)
{
var baseCssData = CssData.Parse(AvaloniaAdapter.Instance, (string) e.NewValue);
control._baseCssData = baseCssData;
htmlContainer.SetHtml(control.Text, baseCssData);
}
else if (e.Property == TextProperty)
{
htmlContainer.ScrollOffset = new Point(0, 0);
htmlContainer.SetHtml((string) e.NewValue, control._baseCssData);
control.InvalidateMeasure();
control.InvalidateVisual();
if (control.VisualRoot != null)
{
control.InvokeMouseMove();
}
}
}
}
private void OnLoadComplete(object sender, EventArgs e)
{
if (CheckAccess())
OnLoadComplete(e);
else
Dispatcher.UIThread.InvokeAsync(() => OnLoadComplete(e)).Wait();
}
private void OnLinkClicked(object sender, HtmlLinkClickedEventArgs e)
{
if (CheckAccess())
OnLinkClicked(e);
else
Dispatcher.UIThread.InvokeAsync(() => OnLinkClicked(e)).Wait();
}
private void OnRenderError(object sender, HtmlRenderErrorEventArgs e)
{
if (CheckAccess())
OnRenderError(e);
else
Dispatcher.UIThread.InvokeAsync(() => OnRenderError(e)).Wait();
}
private void OnStylesheetLoad(object sender, HtmlStylesheetLoadEventArgs e)
{
if (CheckAccess())
OnStylesheetLoad(e);
else
Dispatcher.UIThread.InvokeAsync(() => OnStylesheetLoad(e)).Wait();
}
private void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
{
if (CheckAccess())
OnImageLoad(e);
else
Dispatcher.UIThread.InvokeAsync(() => OnImageLoad(e)).Wait();
}
private void OnRefresh(object sender, HtmlRefreshEventArgs e)
{
if (CheckAccess())
OnRefresh(e);
else
Dispatcher.UIThread.InvokeAsync(() => OnRefresh(e)).Wait();
}
}
}