title: Button.Click in Custom control
body: <p>I want to create a new custom control derived from ContentControl (it will be a container for other controls in a window), but I want a button to close it. (in fact I want a borderless window, but with system-like button to close it).</p>
  
  <p>So I created the Style for the control which contains a Grid with two rows, in the upper row there's a StackPanel with a single button.</p>
  
  <p>How can I bind the Click event of the button to the control itself, to raise an event, or even to send Close command to the parent window?
  </p>
  
  <pre><code>&lt;Grid&gt;
  &lt;Grid.RowDefinitions&gt;
      &lt;RowDefinition Height="20" /&gt;
      &lt;RowDefinition /&gt;
  &lt;/Grid.RowDefinitions&gt;
  &lt;Border Background="Azure" Grid.Row="0"&gt;
      &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;Button HorizontalAlignment="Right" Content="X" Click="Close_Click" /&gt;
      &lt;/StackPanel&gt;
      &lt;/Border&gt;
  &lt;ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>And the code behind:
  </p>
  
  <pre><code>static STContentControl()
  {
  DefaultStyleKeyProperty.OverrideMetadata(typeof(STContentControl), new FrameworkPropertyMetadata(typeof(STContentControl)));
  }
  
  public void Close_Click(object sender, RoutedEventArgs ea)
  {
  
  }
  </code></pre>