Table of Contents

Class HtmlControl

Namespace
TheArtOfDev.HtmlRenderer.WPF
Assembly
StockSharp.Xaml.dll

Provides HTML rendering using the text property.
WPF control that will render html content in it's client rectangle.
The control will handle mouse and keyboard events on it to support html text selection, copy-paste and mouse clicks.

The major differential to use HtmlPanel or HtmlLabel is size and scrollbars.
If the size of the control depends on the html content the HtmlLabel should be used.
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.

LinkClicked event:

Raised when the user clicks on a link in the html.
Allows canceling the execution of the link.

StylesheetLoad event:

Raised when a stylesheet is about to be loaded by file path or URI by link element.
This event allows to provide the stylesheet manually or provide new source (file or uri) to load from.
If no alternative data is provided the original source will be used.

ImageLoad event:

Raised when an image is about to be loaded by file path or URI.
This event allows to provide the image manually, if not handled the image will be loaded from file or download from URI.

RenderError event:

Raised when an error occurred during html rendering.
public class HtmlControl : Control, IAnimatable, IFrameworkInputElement, IInputElement, ISupportInitialize, IQueryAmbient
Inheritance
HtmlControl
Implements
Derived
Inherited Members
Extension Methods

Constructors

HtmlControl()

Creates a new HtmlPanel and sets a basic css for it's styling.

protected HtmlControl()

Fields

AvoidImagesLateLoadingProperty

public static readonly DependencyProperty AvoidImagesLateLoadingProperty

Field Value

DependencyProperty

BaseStylesheetProperty

public static readonly DependencyProperty BaseStylesheetProperty

Field Value

DependencyProperty

HtmlContainer

Underline html container instance.

protected readonly HtmlContainer HtmlContainer

Field Value

HtmlContainer

ImageLoadEvent

Raised when an image is about to be loaded by file path or URI.

public static readonly RoutedEvent ImageLoadEvent

Field Value

RoutedEvent

IsContextMenuEnabledProperty

public static readonly DependencyProperty IsContextMenuEnabledProperty

Field Value

DependencyProperty

IsSelectionEnabledProperty

public static readonly DependencyProperty IsSelectionEnabledProperty

Field Value

DependencyProperty

LinkClickedEvent

Raised when the user clicks on a link in the html.

public static readonly RoutedEvent LinkClickedEvent

Field Value

RoutedEvent

LoadCompleteEvent

Raised when the html document has been fully loaded.

public static readonly RoutedEvent LoadCompleteEvent

Field Value

RoutedEvent

RefreshEvent

Raised when the html document has been fully loaded.

public static readonly RoutedEvent RefreshEvent

Field Value

RoutedEvent

RenderErrorEvent

Raised when an error occurred during html rendering.

public static readonly RoutedEvent RenderErrorEvent

Field Value

RoutedEvent

StylesheetLoadEvent

Raised when a stylesheet is about to be loaded by file path or URI by link element.

public static readonly RoutedEvent StylesheetLoadEvent

Field Value

RoutedEvent

TextProperty

public static readonly DependencyProperty TextProperty

Field Value

DependencyProperty

Properties

AvoidImagesLateLoading

Gets or sets a value indicating if image loading only when visible should be avoided (default - false).
True - images are loaded as soon as the html is parsed.
False - images that are not visible because of scroll location are not loaded until they are scrolled to.

public bool AvoidImagesLateLoading { get; set; }

Property Value

bool

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).
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.
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.

BaseStylesheet

Set base stylesheet to be used by html rendered in the panel.

public string BaseStylesheet { get; set; }

Property Value

string

IsContextMenuEnabled

Is the build-in context menu enabled and will be shown on mouse right click (default - true)

public bool IsContextMenuEnabled { get; set; }

Property Value

bool

IsSelectionEnabled

Is content selection is enabled for the rendered html (default - true).
If set to 'false' the rendered html will be static only with ability to click on links.

public bool IsSelectionEnabled { get; set; }

Property Value

bool

SelectedHtml

Copy the currently selected html segment with style.

[Browsable(false)]
public virtual string SelectedHtml { get; }

Property Value

string

SelectedText

Get the currently selected text segment in the html.

[Browsable(false)]
public virtual string SelectedText { get; }

Property Value

string

Text

Gets or sets the text of this panel

public string Text { get; set; }

Property Value

string

Methods

ClearSelection()

Clear the current selection.

public void ClearSelection()

GetElementRectangle(string)

Get the rectangle of html element as calculated by html layout.
Element if found by id (id attribute on the html element).
Note: to get the screen rectangle you need to adjust by the hosting control.

public virtual Rect? GetElementRectangle(string elementId)

Parameters

elementId string

the id of the element to get its rectangle

Returns

Rect?

the rectangle of the element or null if not found

GetHtml()

Get html from the current DOM tree with inline style.

public virtual string GetHtml()

Returns

string

generated html

HtmlHeight(Size)

Get the width the HTML has to render in (not including vertical scroll iff it is visible)

protected virtual double HtmlHeight(Size size)

Parameters

size Size

Returns

double

HtmlWidth(Size)

Get the width the HTML has to render in (not including vertical scroll iff it is visible)

protected virtual double HtmlWidth(Size size)

Parameters

size Size

Returns

double

InvokeMouseMove()

call mouse move to handle paint after scroll or html change affecting mouse cursor.

protected virtual void InvokeMouseMove()

OnImageLoad(HtmlImageLoadEventArgs)

Propagate the image load event from root container.

protected virtual void OnImageLoad(HtmlImageLoadEventArgs e)

Parameters

e HtmlImageLoadEventArgs

OnKeyDown(KeyEventArgs)

Handle key down event for selection, copy and scrollbars handling.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

OnLinkClicked(HtmlLinkClickedEventArgs)

Propagate the LinkClicked event from root container.

protected virtual void OnLinkClicked(HtmlLinkClickedEventArgs e)

Parameters

e HtmlLinkClickedEventArgs

OnLoadComplete(EventArgs)

Propagate the LoadComplete event from root container.

protected virtual void OnLoadComplete(EventArgs e)

Parameters

e EventArgs

OnMouseDoubleClick(MouseButtonEventArgs)

Handle mouse double click to select word under the mouse.

protected override void OnMouseDoubleClick(MouseButtonEventArgs e)

Parameters

e MouseButtonEventArgs

OnMouseDown(MouseButtonEventArgs)

Handle mouse down to handle selection.

protected override void OnMouseDown(MouseButtonEventArgs e)

Parameters

e MouseButtonEventArgs

OnMouseLeave(MouseEventArgs)

Handle mouse leave to handle cursor change.

protected override void OnMouseLeave(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseMove(MouseEventArgs)

Handle mouse move to handle hover cursor and text selection.

protected override void OnMouseMove(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseUp(MouseButtonEventArgs)

Handle mouse up to handle selection and link click.

protected override void OnMouseUp(MouseButtonEventArgs e)

Parameters

e MouseButtonEventArgs

OnRefresh(HtmlRefreshEventArgs)

Handle html renderer invalidate and re-layout as requested.

protected virtual void OnRefresh(HtmlRefreshEventArgs e)

Parameters

e HtmlRefreshEventArgs

OnRender(DrawingContext)

Perform paint of the html in the control.

protected override void OnRender(DrawingContext context)

Parameters

context DrawingContext

OnRenderError(HtmlRenderErrorEventArgs)

Propagate the Render Error event from root container.

protected virtual void OnRenderError(HtmlRenderErrorEventArgs e)

Parameters

e HtmlRenderErrorEventArgs

OnStylesheetLoad(HtmlStylesheetLoadEventArgs)

Propagate the stylesheet load event from root container.

protected virtual void OnStylesheetLoad(HtmlStylesheetLoadEventArgs e)

Parameters

e HtmlStylesheetLoadEventArgs

Events

ImageLoad

Raised when an image is about to be loaded by file path or URI.
This event allows to provide the image manually, if not handled the image will be loaded from file or download from URI.

public event RoutedEventHandler<HtmlImageLoadEventArgs> ImageLoad

Event Type

RoutedEventHandler<HtmlImageLoadEventArgs>

LinkClicked

Raised when the user clicks on a link in the html.
Allows canceling the execution of the link.

public event RoutedEventHandler<HtmlLinkClickedEventArgs> LinkClicked

Event Type

RoutedEventHandler<HtmlLinkClickedEventArgs>

LoadComplete

Raised when the set html document has been fully loaded.
Allows manipulation of the html dom, scroll position, etc.

public event RoutedEventHandler LoadComplete

Event Type

RoutedEventHandler

RenderError

Raised when an error occurred during html rendering.

public event RoutedEventHandler<HtmlRenderErrorEventArgs> RenderError

Event Type

RoutedEventHandler<HtmlRenderErrorEventArgs>

StylesheetLoad

Raised when a stylesheet is about to be loaded by file path or URI by link element.
This event allows to provide the stylesheet manually or provide new source (file or uri) to load from.
If no alternative data is provided the original source will be used.

public event RoutedEventHandler<HtmlStylesheetLoadEventArgs> StylesheetLoad

Event Type

RoutedEventHandler<HtmlStylesheetLoadEventArgs>