Adding New Items to the WPF Editor Toolbar

Adding toolbar items: the supported ways

The WpfHtmlEditor keeps its built-in factory toolbars exactly as they are; you append your own items. There is no "edit the toolbar on the design surface" mode -- on WPF you add items the WPF way: in code, in XAML, or via data binding (MVVM). The control exposes the toolbars as collections you add to: Toolbar1Items / Toolbar2Items (ItemCollections) and Toolbar1ItemsSource / Toolbar2ItemsSource (bindable dependency properties).

Add an item in code

Create a WPF control, wire its event, and add it to Toolbar1Items after InitializeComponent(). Content.InsertHtml inserts at the caret, manages undo, and raises the change notification.

C#

var btn = new Button { Content = "Insert Disclosure" };
btn.Click += (s, e) =>
    Editor.Content.InsertHtml("<p>Approved compliance text...</p>", moveCaretAfterInsertedContent: true);
Editor.Toolbar1Items.Add(btn);

Add an item in XAML or via data binding (MVVM)

For MVVM, bind a collection from your view-model to Toolbar1ItemsSource (or Toolbar2ItemsSource); your items render alongside the factory buttons. Bind each item's command to a view-model ICommand that calls into the editor.

XAML

<wpfeditor:WpfHtmlEditor x:Name="Editor"
                         Toolbar1ItemsSource="{Binding MyToolbarButtons}" />

Either approach is additive -- the built-in buttons stay; your items are appended.

What you can do from the item event

From your button's event handler (or bound command) you have the editor's whole public surface, and you do not manage undo or change-tracking yourself:

  • Editor.Content -- insert HTML at the caret, get/set the body HTML, open files, read the current document.
  • Editor.Formatting -- bold, italic, font name/size, indent, lists, headings.
  • Editor.Selection -- read or change the current selection.
  • Editor.StateQuery -- ask whether the caret is inside a table, hyperlink, image, etc.

Design-time note

WPF has no Smart Tag, and the WPF design-time support assembly targets .NET Framework only. The full design-time story -- the Properties window, XAML, and how this differs between .NET Framework and modern .NET -- is covered in its own page: see Design-time configuration: the Properties window and XAML in the Start Up section. None of that affects toolbar items, which are always added in code, XAML, or by binding as shown above.

Last updated on May 18, 2026