# Adding Logic Behind the ToolbarButton Click Event

## Content



This topic shows how to add logic behind the C1ToolbarButton **Click** event for **C1ToolbarButtons** through XAML representation and then adding the code for the method in the Code Editor.

1.  Add a **C1ToolbarButton** to the C1Toolbar element in the XAML editor and set the [LabelTitle](/componentone/api/wpf/online-toolbar/dotnet-framework-api/C1.WPF.Toolbar.4.6.2/C1.WPF.Toolbar.C1ToolbarButton.LabelTitle.html) property to **Search**.
    
    ```xml
    <c1:C1Toolbar Grid.Row="1" Height="100" Name="c1Toolbar1">
       <c1:C1ToolbarButton LabelTitle="Search"
    </c1:C1Toolbar>
    ```
    
2.  Add an attribute named **Click** to the **C1ToolbarButton** element in the XAML editor, and set its value to **New Click**. This is the name that you will give the event handler in code. Also give the **C1ToolbarButton** element a unique name and set its value to Search.
    
    ```xml
    <c1:C1Toolbar Grid.Row="1" Height="100" Name="c1Toolbar1">
        <c1:C1ToolbarButton LabelTitle="Search" Click="New_Click" Name="Search"/>
    </c1:C1Toolbar>
    ```
    
3.  Right-click the designer and then click **View Code**.
4.  Add the following event handler to the Window1 class. This code displays a message whenever you click the button.
    
    ```csharp
    private void New_Click(object sender, RoutedEventArgs e)
    {
      MessageBox.Show("Event handler was created by clicking the " + Search);
    }
    ```
    

**Run the application and observe**:

The name of the toolbar button appears in the message box:

**![](https://cdn.mescius.io/document-site-files/images/17ce8aee-69c7-489e-8aef-ce88c8948853/adding_logic_behind_the_toolbarbutton_click_event_files/image001.png)**