Articles in this section
Category / Section

How to Handle Custom Toolbar in Xamarin.Forms SfRichTextEditor?

1 min read

How to handle the Custom Toolbar in the SfRichTextEditor

 

Thise article explains how to handle the Customer Toolbar in Xamarin.Forms Rich Text Editor.

 

Step 1:

Create a SfRichTextEditor sample with all the necessary assemblies. Refer to this Getting started documentation to create and configure a simple SfRichTextEditor sample and configure i.t.

 

Step 2:

Use the Custom Toolbar to track the Toolbars items in the SfRichTextEditor.

 

XAML:

 

<rte:SfRichTextEditor VerticalOptions="FillAndExpand" PlaceHolder="Type something" x:Name="richTextEditor"/>

 

 

C#:

 SfRichTextEditor richTextEditor = new SfRichTextEditor();

  richTextEditor.PlaceHolder = "Type something";

 ObservableCollection<object> collection = new ObservableCollection<object>();

 collection.Add(ToolbarOptions.Bold);

 collection.Add(ToolbarOptions.Italic);

 collection.Add(ToolbarOptions.Underline);

 collection.Add(ToolbarOptions.NumberList);

 collection.Add(ToolbarOptions.BulletList);

 

 Button emojiButton = new Button();

 emojiButton.BackgroundColor = Color.Transparent;

 emojiButton.HeightRequest = 50;

 emojiButton.WidthRequest = 50;

 emojiButton.Text = "\U0001F642";

 collection.Add(emojiButton);

 emojiButton.Clicked += EmojiButton_Clicked;

 richTextEditor.ToolbarItems = collection;

 this.Content = richTextEditor;

 

 private void EmojiButton_Clicked(object sender, EventArgs e)

  {

     richTextEditor.InsertHTMLText("😊");

  }

 

 

 

Remove an item from the custom toolbar collection:

C#:

SfRichTextEditor richTextEditor = new SfRichTextEditor();

  richTextEditor.PlaceHolder = "Type something";

 ObservableCollection<object> collection = new ObservableCollection<object>();

 collection.Add(ToolbarOptions.Bold);

 collection.Add(ToolbarOptions.Italic);

 collection.Add(ToolbarOptions.Underline);

 collection.Add(ToolbarOptions.NumberList);

 collection.Add(ToolbarOptions.BulletList);

 

 Button emojiButton = new Button();

 emojiButton.BackgroundColor = Color.Transparent;

 emojiButton.HeightRequest = 50;

 emojiButton.WidthRequest = 50;

 emojiButton.Text = "\U0001F642";

 collection.Add(emojiButton);

 emojiButton.Clicked += EmojiButton_Clicked;

 richTextEditor.ToolbarItems = collection;

 this.Content = richTextEditor;

 

 

 //Remove an item from the custom toolbar collection

 Collection.RemoveAt(0);

 Collection.Remove(emojiButton);

 

 

 private void EmojiButton_Clicked(object sender, EventArgs e)

  {

     richTextEditor.InsertHTMLText("😊");

  }

 

The sample that explains how to track the font changes using the Custom Toolbar in the Rich Text Editor can be downloaded sample here.


Conclusion

I hope you enjoyed learning about how to handle custom toolbar in Xamarin.Forms RichTextEditor.

You can refer to our Xamarin.Forms Rich Text Editor feature tour page to know about its other groundbreaking feature representations documentation  to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied