Componentone Toolbar for WPF and Silverlight
Commanding with C1Toolbar (WPF Tutorial) / Part 1: Using the Command Library
In This Topic
    Part 1: Using the Command Library
    In This Topic

    WPF provides a library of predefined commands such as the following:

    Many WPF controls have built-in support for these commands so you can implement them without having to write code.

    The following steps show how to implement some common clipboard commands using C1Toolbar.

    1. Open or create a new WPF application.
    2. Add two RowDefinitions to the default Grid element, giving the first row an automatic height, such as this:

      XAML
      Copy Code
      <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition />
      </Grid.RowDefinitions>
      

    3. Add a C1Toolbar to the fill the first row.
    4. Paste the following XAML to fill C1Toolbar with some tabs, groups and buttons:

      XAML
      Copy Code
      <c1:C1Toolbar Name="c1Toolbar1" FocusManager.IsFocusScope="True">
          <c1:C1ToolbarTabControl>
              <c1:C1ToolbarTabItem Header="Home">
                  <c1:C1ToolbarGroup Header="Clipboard">
                      <c1:C1ToolbarButton LabelTitle="Paste" Command="ApplicationCommands.Paste" LargeImageSource="/Resources/paste.png" />
                      <c1:C1ToolbarButton LabelTitle="Cut" Command="ApplicationCommands.Cut" SmallImageSource="/Resources/cut.png" />
                      <c1:C1ToolbarButton LabelTitle="Copy" Command="ApplicationCommands.Copy" SmallImageSource="/Resources/copy.png" />
                  </c1:C1ToolbarGroup>
              </c1:C1ToolbarTabItem>
          </c1:C1ToolbarTabControl>
      </c1:C1Toolbar>
      

      This markup creates a single tab containing a single group inside C1Toolbar. The Clipboard group contains three C1ToolbarButtons each assigned a common clipboard command from the WPF application command library. Notice the attached IsFocusScope property is set to True for C1Toolbar. This enables C1Toolbar to keep track of the focused element within its scope. Small and large images are also specified for the C1ToolbarButtons, although these are not required.

    5. Add a TextBox control below C1Toolbar.
    6. Run the application and notice that the common clipboard commands (Paste, Copy and Cut) work in the TextBox by clicking the C1ToolbarButtons.