Version

Binding xamRichTextEditor to Data

Topic Overview

Purpose

This topic explains how to use document adapters for binding the xamRichTextEditor ™ control to various data sources.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides an overview of the features supported by the xamRichTextEditor control.

This topic explains the document’s content logical structure you can use to edit the contents in the xamRichTextEditor programmatically.

This topic provides detailed instructions to help you get up and running as quickly as possible with the xamRichTextEditor .

Introduction to Document Adapters

Document adapters summary

You can use the document adapters to bind the xamRichTextEditor’s document to various data formats. The following table lists the available document adapters and the NuGet packages in which they are located:

Document Adapter NuGet Package

Infragistics.WPF.RichTextDocument

Infragistics.WPF.RichTextDocument.Rtf

Infragistics.WPF.RichTextDocument.Word

Infragistics.WPF.RichTextDocument.Html

Configuring Document Adapters

Overview

To be able to use the document adapters there are some key properties that first must be set.

Key properties

The following table maps the desired configuration to its specific property settings.

Property Purpose

An instance of RichTextDocument from or to which content will be obtained or added.

Value

Individually defined, in each adapter, this property consists of various type, string for plain text and RTF format and as byte array for DOCX format, depending on the adapter’s purpose.

Specify when the Value should be refreshed. Use one of the following RichTextRefreshTrigger values.

  • Explicit – Prevents the Value from automatically refreshing. You must call the RefreshValue method on the adapter to update the Value.

  • Delayed – The DelayAfterFirstEdit and DelayAfterLastEdit intervals can be set to non-null values to specify delays after certain user edits when the Value should be refreshed. If neither is set, this trigger will act like the Explicit trigger.

  • ContentChanged – Refreshes the Value after every edit by the user.

Note
Note

Only use this trigger in editors with a small amount of content as large documents could cause performance issues.

  • LostFocus ( default value ) – Refreshes the Value after the user leaves the editor hosting the RichTextDocument. Displaying the document in anything other than the editor causes the trigger will act like the Explicit trigger.

The nullable interval after the first edit of the RichTextDocument for refreshing the Value. Only use this interval when the RefreshTrigger is set to Delayed. Where the “first edit” is the initial edit following the display of the document or the first edit after the previous refresh of the Value property. This delay can be used in conjunction with DelayAfterLastEdit. The first delay which elapses refreshes the Value.

The nullable interval after the last edit of the RichTextDocument for refreshing the Value . Only use this interval when the RefreshTrigger is set to Delayed. Where the “last edit” is the most recent edit by user. If this delay has not yet elapsed when the user makes another edit , the timer resets and the full interval will need to elapse again before refreshing the Value. Using this delay in conjunction with DelayAfterFirstEdit allows you to [finish sentence]. The first delay which elapses refreshes the Value.

Key methods

The following table maps the desired behavior to its specific method.

Method Purpose

This method forces the content of the RichTextDocument to reflect any new values set on the adapter by calling RefreshDocumentCore() if and only if, the new values have not yet been converted to document content.

This method calls RefreshValueCore() if there are changes on the document not yet pushed into adapter’s exposed values .

Key Events

Event Purpose

This event is raised when an exception is thrown while attempting to load a document.

Document Adapters Specifics

Overview

The following tables list the other members exposed by the supported document adapters.

Adapter specific properties

PlainTextDocumentAdapter

Member Description

Specifies various options to use when determining how to down-convert rich text content to plain text or up-convert plain text content to rich text.

A string containing the plain text content of the RichTextDocument.

RtfDocumentAdapter

Member Description

A string containing the RTF content of the RichTextDocument.

WordDocumentAdapter

Member Description

Defines the format for saving the Value. This setting is not used when loading the data because the format can be inferred from the data. Currently supported values:

  • StrictOpenXml – The DOCX, Strict Open XML file format.

  • Word2007Document – The DOCX file format introduced in Word 2007.

A byte array containing the Word file format content of the RichTextDocument.

HtmlDocumentAdapter

Member Description

Specify the base address from which relative files will be loaded/saved.

Note
Note

A new base URI can be specified in the HTML document with the <base> header tag.

Specify how images are saved.

Returns or sets a relative or absolute path where external files, like images, are written to.

Returns or sets whether to save relative or absolute local file paths.

A string with the HTML content of the RichTextDocument .

Document Adapters Examples

Examples

The code snippets below illustrates how to use document adapters to bind the xamRichTextEditor’s document to some content:

In XAML:

<ig:RtfDocumentAdapter
    Document="{Binding Path=Document, ElementName=xamRichTextEditor1}"
    Value="{Binding RtfData, Mode=TwoWay}"
    RefreshTrigger="Delayed"
    DelayAfterLastEdit="00:00:10.00" />
<ig:XamRichTextEditor x:Name="xamRichTextEditor1" />
<ig:WordDocumentAdapter
    Document="{Binding Path=Document, ElementName=xamRichTextEditor1}"
    Value="{Binding Path=WordData, Mode=TwoWay}"
    Format="StrictOpenXml" />
<ig:XamRichTextEditor x:Name="xamRichTextEditor1" />
<ig:HtmlDocumentAdapter
    Document="{Binding Path=Document, ElementName=xamRichTextEditor1}"
    Value="{Binding Path=HtmlData, Mode=TwoWay}"
    BaseUri="C:\\WebSites\\"
    LocalFilePath="MyWebSite1"
    SaveAbsoluteLocalFilePaths="True" />
<ig:XamRichTextEditor x:Name="xamRichTextEditor1" />
Note
Note

The code snippet above demonstrating the HTML document adapter will cause the adapter to save the external content, such as images, under "C:\\WebSites\\MyWebSite1".

Related Content

Topics

The following topic provides additional information related to this topic.

Topic Purpose

The topics in this group provide information about rich text content import and export.