Adding New Items on Factory Toolbars

The screenshot below shows the two factory toolbars: Toolbar1 and Toolbar2


You can add new buttons to the factory toolbars either in XAML or programmatically (C#, VB.NET).

Adding new buttons in XAML

Example of two additional buttons in the toolbars is below:

<wpfHtmlEditor:WpfHtmlEditor x:Name="WpfHtmlEditor" Grid.Row="1">
        <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="AdditionalButton1_OnClick">Additional button1</Button>
        <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="AdditionalButton2_OnClick">Additional button2</Button>

Collections Toolbar1Items and Toolbar2Items allow you to add additional buttons on Toolbar1 and Toolbar2 accordingly. Result is below:

Additional toolbar buttons

Adding new buttons programmatically

You can add buttons programmatically to the toolbars already available in the HTML Editor. The WpfHtmlEditor class provides two properties – Toolbar1 and Toolbar2.

In the code snippet below, we have added a Signature button to the first Toolbar (Toolbar1). This button inserts a predefined HTML text in the Editor at the current cursor location.


private void Window1_OnLoaded(object sender, RoutedEventArgs e)
    Button btnSignature = new Button();
    btnSignature.Content = "Signature";
    btnSignature.Click += btnSignature_Click;
    btnSignature.BorderBrush = Brushes.Black;
    btnSignature.BorderThickness = new Thickness(1);

void btnSignature_Click(object sender, RoutedEventArgs e)
    wpfHtmlEditor1.Content.InsertHtml("<p>James Paul <br/><span style=\"color:blue;\">Executive Officer</span><br /></p>", keepSelected: false);


Private Sub Window1_Loaded(sender As Object, e As RoutedEventArgs)
     Dim btnSignature As New Button()
     btnSignature.Content = "Signature"
     AddHandler btnSignature.Click, AddressOf btnSignature_Click
     btnSignature.BorderBrush = Brushes.Black
     btnSignature.BorderThickness = New Thickness(1)
End Sub
Private Sub btnSignature_Click(sender As Object, e As RoutedEventArgs)
     htmlEditor1.Content.InsertHtml("<p>James Paul <br/><span style=""color:blue;"">Executive Officer</span><br /></p>", False)
End Sub

Additional button Signature

Last updated on May 28, 2015