2. Adding a Menu Bar

The last step is to add a menu strip to the Window. Switch back to the Design/XAML view. In the toolbox, look for the Menu control in the Controls category and double-click the icon to insert it to the current Window. In the Properties window, change the DockPanel.Dock property to Top.

In the XAML, re-arrange the elements, so that the menu is the first element in the DockPanel and remove the Width and Height properties:

Instead of adding the menu entries using the Properties window, the entries are added in the XAML directly which is much faster. Replace the menu element with the following XAML code:

<Menu Name="menu1" DockPanel.Dock="Top">
 <MenuItem Header="_File">
  <MenuItem Header="Load..." Click="MenuItemLoad_Click" />
  <MenuItem Header="Save..." Click="MenuItemSave_Click" />
  <Separator />
  <MenuItem Header="Exit" Click="MenuItemExit_Click" />
 </MenuItem>
 <MenuItem Header="_Edit">
  <MenuItem Header="Cut" Click="MenuItemCut_Click" />
  <MenuItem Header="Copy" Click="MenuItemCopy_Click" />
  <MenuItem Header="Paste" Click="MenuItemPaste_Click" />
 </MenuItem>
 <MenuItem Header="_Format">
  <MenuItem Header="Character..." Click="MenuItemCharacter_Click" />
  <MenuItem Header="Paragraph..." Click="MenuItemParagraph_Click" />
 </MenuItem>
</Menu>

In the first XAML menu element Load..., right-click MenuItemLoad_Click and choose Navigate to Event Handler from the opened context menu. This opens the code view of the Window.

Add the following code, so that the complete method looks like this:

[C#]
private void MenuItemLoad_Click(object sender, RoutedEventArgs e)
{
 textControl1.Load();
}
[Visual Basic]
Private Sub MenuItemLoad_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
 TextControl1.Load
End Sub

Repeat this step for all menu items and add the following code to the code view:

[C#]
private void MenuItemSave_Click(object sender, RoutedEventArgs e)
{
 textControl1.Save();
}

private void MenuItemExit_Click(object sender, RoutedEventArgs e)
{
 this.Close();
}

private void MenuItemCut_Click(object sender, RoutedEventArgs e)
{
 textControl1.Cut();
}

private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
{
 textControl1.Copy();
}

private void MenuItemPaste_Click(object sender, RoutedEventArgs e)
{
 textControl1.Paste();
}

private void MenuItemCharacter_Click(object sender, RoutedEventArgs e)
{
 textControl1.FontDialog();
}

private void MenuItemParagraph_Click(object sender, RoutedEventArgs e)
{
 textControl1.ParagraphFormatDialog();
}
[Visual Basic]
Private Sub MenuItemSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
{
 TextControl1.Save
}

Private Sub MenuItemExit_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
{
 Me.Close
}

Private Sub MenuItemCut_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
{
 TextControl1.Cut
}

Private Sub MenuItemCopy_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
{
 TextControl1.Copy
}

Private Sub MenuItemPaste_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
{
 TextControl1.Paste
}

Private Sub MenuItemCharacter_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
{
 TextControl1.FontDialog
}

Private Sub MenuItemParagraph_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
{
 TextControl1.ParagraphFormatDialog
}

Press F5 to start the project.