Overview
RichTextEditor control allows you to add (insert), cut, copy, paste, resize, and delete images by using built-in toolbar items.
You can add images in the RichTextEditor by using the predefined toolbar items:
The Working with Images is part of Telerik UI for .NET MAUI, the most comprehensive UI suite for .NET MAUI! To try it out, sign up for a free 30-day trial and kickstart your cross-platform app development today.
-
RichTextEditorAddImageToolbarItem
—Allows you to add an image—the RichTextEditorPickImage
event is fired, so you can handle the logic for selecting an image. The toolbar is enabled if no image is selected. -
RichTextEditorAddOrEditImageToolbarItem
—Adds or edits images depending whether image is selected. If image is selected, the editor opens a dialog to edit the image. If image is not selected, thePickImage
event fires. -
RichTextEditorImageNavigationToolbarItem
—Adds images or navigates to additional toolbar items depending whether image is selected. If image is selected, the editor navigates to image operation toolbar items. If image is not selected, thePickImage
event fires.
You can insert images from URI, Data(byte []), Stream, File. The image source is of type RichTextImageSource
.
RichTextImageSource FromData(byte[] data, RichTextImageType type)
RichTextImageSource FromFile(string path)
RichTextImageSource FromFile(string path, RichTextImageType type)
RichTextImageSource FromStream(Stream stream, RichTextImageType type)
RichTextImageSource FromStream(Func<Stream> stream, RichTextImageType type)
RichTextImageSource FromStream(Func<Task<Stream>> stream, RichTextImageType type)
RichTextImageSource FromStream(Func<CancellationToken, Task<Stream>> stream, RichTextImageType type)
RichTextImageSource FromUrl(string uri)
Also you have to point out the image format type. The supported image format types(of type RichTextImageType
) are:
Gif
Jpeg
Png
Svg
Webp
Required Permissions
If you want to work with images from the device gallery, then you have to grant the required permissions to the RichTextEditor.
To enable the users to add images by using the predefined toolbar items, use RichTextEditorAddOrEditImageToolbarItem
on desktop and RichTextEditorImageNavigationToolbarItem
on mobile platforms. Both toolbar items provide a way to pick an image directly. The RichTextEditor PickImage
event is fired. You need to manually implement the logic for selecting an image inside the PickImage
event handler.
private void OnPickImage(object sender, Telerik.Maui.Controls.RichTextEditor.PickImageEventArgs e)
{
// add your custom logic here
}
Events
-
PickImage
—Raised when the user has requested to pick an image in theRadRichTextEditor
. ThePickImage
event handler receives two parameters:- The
sender
, which is the RichTextEditor control; -
PickImageEventArgs
provides the following methods:-
Accept
—Invoke this method when the user has picked an image. Receives one parameterimagesource
of typeRichTextImageSource
(Specifies theRichTextImageSource
for the picked image); -
Cancel
—Invoke this method when the user has canceled the operation;
-
- The
-
InsertImageError
—Raised when trying to insert an image in theRadRichTextEditor
. TheInsertImageError
event handler receives two parameters:- The
sender
, which is the RichTextEditor control; -
InsertImageErrorEventArgs
provides the following methods:-
Source
—Of typeRichTextImageSource
. The property allows you to get the source of the image (read-only property). -
Error
—Of typeException
. Specifies the exception that is raised when image cannot be inserted.
-
- The
-
IsImageSelectedChanged
—Raised when an image inside the editor is selected. TheIsImageSelectedChanged
event handler receives two parameters:- The
sender
, which is the RichTextEditor control; -
RadValueChangedEventArgs<bool>
, which provides theNewValue
andPreviousValue
properties of typeTValue
.
- The
Methods
- The
GetImageAsync
method asynchronously returns an object of typeRichTextImage
which represents the current selected image (ornull
if no image is available). TheRichTextImage
object contains the source, title, width, height of the image.
Commands
-
InsertImageCommand
(ICommand
)—Used to insert images in the editor. The command takes a single parameter of typeRichTextImage
. TheRichTextImage
object contains the source, title, width, height of the image. If you do not set width and height explicitly, the image will be added with its original size. -
RemoveImageCommand
(ICommand
)—Uses for removing images from the editor.