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"> <wpfHtmlEditor:WpfHtmlEditor.Toolbar1Items> <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="AdditionalButton1_OnClick">Additional button1</Button> </wpfHtmlEditor:WpfHtmlEditor.Toolbar1Items> <wpfHtmlEditor:WpfHtmlEditor.Toolbar2Items> <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="AdditionalButton2_OnClick">Additional button2</Button> </wpfHtmlEditor:WpfHtmlEditor.Toolbar2Items> </wpfHtmlEditor:WpfHtmlEditor>
Collections Toolbar1Items and Toolbar2Items allow you to add additional buttons on Toolbar1 and Toolbar2 accordingly. Result is below:
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.
C#
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); wpfHtmlEditor1.Toolbar1.ToolBar.Items.Add(btnSignature); } void btnSignature_Click(object sender, RoutedEventArgs e) { wpfHtmlEditor1.Content.InsertHtml("<p>James Paul <br/><span style=\"color:blue;\">Executive Officer</span><br />james_paul@some_domain.com</p>", keepSelected: false); }
VB.NET
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) htmlEditor1.Toolbar1.Toolbar.Items.Add(btnSignature) 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 />james_paul@some_domain.com</p>", False) End Sub