Overview
WordProcessor is the highest-level component in the RichTextKit Avalonia library.
It composes a DocumentToolBar,
a RichTextEditor canvas, horizontal and vertical
scrollbars, and a menu bar — all pre-wired and ready to use. Just add it to your window.
WordProcessor unless you need to provide a completely custom toolbar layout or scrollbar behavior.
For those cases, compose RichTextEditor and DocumentToolBar yourself.
AXAML Usage
<Window
xmlns:pe="clr-namespace:ParentElement.RichText.Avalonia;assembly=ParentElement.RichText.Avalonia">
<pe:WordProcessor
x:Name="Editor"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
</Window>
Properties
| Property | Type | Description |
|---|---|---|
| Document | DocumentController | Shortcut to Canvas.DocumentController. Use this to apply styles, insert text, or read content programmatically. |
| CanvasWidth | double | The pixel width of the inner editor canvas. Updated automatically on resize. |
| TB | DocumentToolBar | Direct reference to the toolbar. Use this to access import/export methods or programmatically invoke toolbar actions. |
Built-in Menu Actions
WordProcessor includes a menu bar that delegates to the toolbar. All file operations open
system file picker dialogs.
| Menu Item | Action |
|---|---|
| File → Import DOCX | Open file picker, import Word document via OpenXmlImporter |
| File → Import RTF | Open file picker, import RTF document via RtfImporter |
| File → Import HTML | Open file picker, import HTML document via HtmlImporter |
| File → Export DOCX | Save file picker, export via OpenXmlExporter |
| File → Export RTF | Save file picker, export via RtfExporter |
| File → Export HTML | Save file picker, export via HtmlExporter |
| Edit → Copy | DocumentController.Copy() |
| Edit → Cut | DocumentController.Cut() |
| Edit → Paste | DocumentController.Paste() |
| Insert → Image | File picker → DocumentController.InsertInlineImage() |
Scrollbar Synchronization
WordProcessor automatically synchronizes its scrollbars with the editor canvas.
Scroll events from the bars call Canvas.ScrollTo(), and
Canvas.ContentSizeChanged updates the scrollbar ranges when the document grows or shrinks.
No extra wiring is needed.
Programmatic Control
// In code-behind (Window.axaml.cs)
// Apply formatting to selected text
await Editor.Document.ApplyBold();
await Editor.Document.ApplyFontSize(18);
// Listen for selection changes
Editor.Document.OnNavigation += (info) => UpdateStatusBar(info);
// Export to HTML
var reader = Editor.Document.GetContentReader();
await new HtmlExporter(reader).ExportAsync("document.html");
// Programmatically trigger import via the toolbar
await Editor.TB.ImportDocx();
Configuring the Document
The toolbar exposes a "Document Settings" button that opens a dialog. You can also configure settings programmatically:
var settings = new DocumentSettings
{
PageWidth = 900f,
DocumentBackgroundColor = SKColors.White,
DocumentMargins = new DocumentMargins(80, 80, 60, 60),
};
Editor.Document.ApplyDocumentSettings(settings);