Getting and Setting HTML Value

Once you have setup 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 usage, BodyHtml is the most common thing to use. You may chose 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 swich 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.

Last updated on 28 May 2015, Thursday, 4:34:08 AM
If you have any questions or concerns about this tutorial, Please feel free to share your comment.