[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Track Changes
    Mail Merge
    Restrictions and Protection
   [Expand]Visual Elements
    HTML Tag Support
    [Expand]UI Customization
      How to: Create a New Document
      How to: Load a Document
      How to: Save a Document
      How To: Export Document to PDF format
      How To: Export Document to HTML format
    [Expand]Text Boxes
     Spell Check
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Load a Document

DXRichEdit allows you to load a document from a file a data stream or a string in code and in XAML.

Determine a moment when the document can be modified using related events

Expanded Load a Document in XAML

Use the RichEditControl.DocumentSource property to bind the DXRichEdit to the document source in XAML. Documents can be loaded from a stream, byte array or from a location specified by the full file path or Uri. An empty document is created if the RichEditControl.DocumentSource property is null.

The following code snippet uses a pack Uri as a document source to load a sample document:

This approach does not save changes made to the document back to database. Refer to the Lesson 4 - Bind the RichEditControl to a Document Source using the MVVM pattern for information on how to save changes.

Expanded Load a Document from File

Expanded Load a Document from a Stream

The format of the document loaded from a stream is detected automatically by the built-in IFormatDetectorService service implementation. The following formats are detected:

  • ODT - non-encrypted files only;

Use the LoadDocument method overloads with explicit format definition to improve performance.

Expanded Load a Document from a String

The following code snippet displays the word "Test" in blue.


A complete sample project is available at https://github.com/DevExpress-Examples/wpf-richedit-document-api-t213968.

Expanded Related Events

The table below lists events related to the document loading:

Event Description
RichEditControl.BeforeImport Occurs before a document is loaded (imported from an external source).
RichEditControl.InitializeDocument Occurs before a document is loaded. Handle this event to set initial document settings.
RichEditControl.DocumentLoaded Occurs after a document is loaded into the RichEdit control.
DocumentLayout.DocumentFormatted Fires after the document layout is calculated.
RichEditControl.InvalidFormatException Fires when the supplied data could not be recognized as data in the assumed format for import.
RichEditControl.UnhandledException This event is raised when an exception unhandled by the DevExpress.XtraRichEdit.RichEditControl occurs.

Is this topic helpful?​​​​​​​