Getting and Setting HTML Value

Once you have set up the control to your form, the first question you would be asking, "How can I set HTML value to the editor and how I can get back the edited HTML value from the editor".

The editor gives you 2 properties for that. BodyHtml and DocumentHtml.

Body HTML property

BodyHTML property will give you the part of the HTML document that is bound by <body></body>tag.
So if your edited document has the following html

<html>
<head><title>Hello page</title></head>
<body style="font-family:arial">
<b> Hello World </b>
</body>
</html>

Then BodyHtml property will return following string

<b> Hello World </b>

When you set this property with an HTML string, the HTML will be placed inside the <body> tags. If you set a full HTML document to this BodyHtml property, the control will extract the inner body part from your full HTML and the BodyHtml property will be set accordingly.

Document HTML property

DocumentHtml property will return the whole html as follows :

<html>
<head><title>Hello page</title></head>
<body style="font-family:arial">
<b> Hello World </b>
</body>
</html> 

For blog contents and other simple snippet usages, BodyHtml is the most common thing to use. You may choose what option (either BodyHtml or DocumentHtml) will be the default option from the property browser or directly from the smart tag.

WPF HTML editor Default HTML Type

Even if you set Default Html Type = BodyHtml, you can get or set DocumentHtml, same way, if you set Default Html Type = DocumentHtml, then, you can get or set BodyHtml. Then, why should you bother with this Default Html Type ? This 'Default Html Type' will be effective when you switch to the HTML Source mode, or whenever you try to save the document using the save button.

If you switch the editor mode to HTML Source mode, then, if your Default Html Type was set to BodyHtml, then, you will be able to see only the body HTML part in the source text editor.

Note: Please do not set both BodyHtml and DocumentHtml. Please choose to use either one of the property consistently. Otherwise, you will experience unexpected results.

Last updated on 28 February 2018, Wednesday, 1:41:59 PM
If you have any questions or concerns about this tutorial, Please feel free to share your comment.