Images in WPF DOCX Editor

18 Aug 20262 minutes to read

The WPF RichTextBox (SfRichTextBoxAdv) allows you to insert images of various formats, including bitmap (.bmp), JPEG (.jpg, .jpeg), and PNG (.png). Metafile images (.wmf, .emf) are not supported.

The following code example illustrates how to insert a picture into the SfRichTextBoxAdv document through the InsertPictureCommand UI command.

<Button Content="Insert Picture" Command="RichTextBoxAdv:SfRichTextBoxAdv.InsertPictureCommand" CommandTarget="{Binding ElementName=richTextBoxAdv}" />

Image resizer

The SfRichTextBoxAdv also supports a built-in image resizer to resize the images present in the document to a size of your choice. The image resizer accepts both touch and mouse interactions.

When an image is selected, the resizer provides drag handles on each corner and at the midpoint of each side. Dragging a corner handle preserves the image’s aspect ratio, while dragging a side handle changes only the corresponding dimension. The resizer can be enabled or disabled through the EditorSettings class.

The following code example illustrates how to disable the image resizer.

SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();
richTextBoxAdv.EditorSettings.EnableImageResizer = false;
Dim richTextBoxAdv As New SfRichTextBoxAdv()
richTextBoxAdv.EditorSettings.EnableImageResizer = False

WPF RichTextBox showing an image selected with the built-in image resizer handles

Text wrapping style

Text wrapping refers to how images fit with surrounding text in a document. Please refer to this page for more information about text wrapping styles available in Word documents.

Positioning the image

Starting from v19.1.0.x, the SfRichTextBoxAdv preserves the position properties of images and displays them accordingly. Users cannot modify these position properties from the UI. When the image is positioned relative to the line or paragraph, it will be automatically moved along with text being edited.

Positioning behavior

  • Images that are positioned relative to the line move automatically as the surrounding text is edited.
  • Floating images (any wrap style other than InLine) keep their position but cannot have their position properties modified through the UI.

Behavior: The image with text wrapping style InLine can only be dragged and dropped anywhere in the document.

NOTE

You can refer to our WPF RichTextBox feature tour page for its groundbreaking feature representations. You can also explore our WPF RichTextBox example to know how to render and configure the editing tool.

See also