title: Click event is not raised for Button in popup on datagrid
body: <p>I'am quite new with WPF and still trying to figure it out in all its details ;)
  I have a strange issue with the button not raising its click event. I have a UserControl called PopupButton which is basically a button with a popup showed on click. The content of the popup is ContentPresenter and is binded to the dependency property called PopupContentHolder on the PopupButton.
  Then on the main form I have a DataGrid with DataGridTemplateColumn where in the  <code>&lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt;</code> I placed my PopupButton. Then I assign a list box with an ItemTemplate as the content of the popup for my PopupButton.
  In simple this looks as follows</p>
  
  <pre><code>&lt;DataGrid HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch"
          HorizontalContentAlignment="Stretch"
          ColumnHeaderHeight="40"
          FontSize="11"
          HorizontalScrollBarVisibility="Disabled"
          ItemsSource="{Binding Pocos}"
          RowHeight="30"
          SnapsToDevicePixels="True"
          VerticalScrollBarVisibility="Disabled"&gt;
  &lt;DataGrid.Columns&gt;
      &lt;DataGridTemplateColumn MinWidth="70" Header="NAme"&gt;
          &lt;DataGridTemplateColumn.CellTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;controls:PopupButton DoPopupOnMainButton="True"
                                          Foreground="{StaticResource HeaderLinkActiveColor}"
                                          MarkButtonOnPopup="True"
                                          PopupBackground="{StaticResource PopupBackground}"
                                          PopupPadding="5"
                                          ShowDownArrow="False"
                                          Text="Some test button"&gt;
                      &lt;controls:PopupButton.PopupContentHolder&gt;
                          &lt;StackPanel&gt;
                              &lt;ListBox Background="Transparent" ItemsSource="{Binding Tenders}"&gt;
                                  &lt;ListBox.ItemTemplate&gt;
                                      &lt;DataTemplate&gt;
                                          &lt;Button Margin="0,2,0,0"
                                                  Click="Button_Click"
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}},
                                                                      Path=DataContext.SaveCommand}"
                                                  Content="{Binding .}"
                                                  FontSize="11" /&gt;
                                      &lt;/DataTemplate&gt;
                                  &lt;/ListBox.ItemTemplate&gt;
                              &lt;/ListBox&gt;
                          &lt;/StackPanel&gt;
                      &lt;/controls:PopupButton.PopupContentHolder&gt;
                  &lt;/controls:PopupButton&gt;
              &lt;/DataTemplate&gt;
          &lt;/DataGridTemplateColumn.CellTemplate&gt;
      &lt;/DataGridTemplateColumn&gt;
  &lt;/DataGrid.Columns&gt;
  </code></pre>
  
  <p></p>
  
  <p>Now the problem is with the button inside the ListBox in PopupButton, Neither Click event nor Command is raised. Moreover when I put the PopupButton outside the DataGrid then everythinkg works perfect. Also when I put above list box directly in grid cell then it works.
  Maybe its something wrong with my PopupButtonControl.</p>
  
  <pre><code>&lt;UserControl x:Class="WpfApplication1.PopupButton"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           x:Name="userControlRoot"
           Width="Auto"
           Height="Auto"&gt;
  &lt;UserControl.Resources&gt;
      &lt;BooleanToVisibilityConverter x:Key="BoolToVis" /&gt;
  
      &lt;Storyboard x:Key="PopupCloseStoryBoard"&gt;
          &lt;BooleanAnimationUsingKeyFrames Storyboard.TargetName="popup" Storyboard.TargetProperty="IsOpen"&gt;
              &lt;DiscreteBooleanKeyFrame KeyTime="0:0:0.1" Value="False" /&gt;
          &lt;/BooleanAnimationUsingKeyFrames&gt;
      &lt;/Storyboard&gt;
  
      &lt;Storyboard x:Key="PopupOpenStoryBoard"&gt;
          &lt;BooleanAnimationUsingKeyFrames Storyboard.TargetName="popup" Storyboard.TargetProperty="IsOpen"&gt;
              &lt;DiscreteBooleanKeyFrame KeyTime="0:0:0.0" Value="True" /&gt;
          &lt;/BooleanAnimationUsingKeyFrames&gt;
      &lt;/Storyboard&gt;
  
  
  &lt;/UserControl.Resources&gt;
  
  &lt;Grid&gt;
  
      &lt;Border x:Name="brdButtonBack"
              Background="Transparent"
              CornerRadius="3,3,0,0"
              Padding="{Binding Padding,
                                ElementName=userControlRoot}" /&gt;
  
      &lt;Button x:Name="btnMain"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Click="btn_Click"
              Command="{Binding MainCommand,
                                ElementName=userControlRoot}"
              Content="{Binding Text,
                                ElementName=userControlRoot}"
              IsEnabled="{Binding IsEnabled,
                                  ElementName=userControlRoot}" /&gt;
  
      &lt;Popup x:Name="popup"
             MinWidth="{Binding ActualWidth,
                                ElementName=userControlRoot}"
             AllowsTransparency="True"
             Placement="Bottom"
             PlacementTarget="{Binding ElementName=brdButtonBack}"
             PopupAnimation="Slide"
             StaysOpen="False"&gt;
          &lt;Border Background="{Binding PopupBackground,
                                       ElementName=userControlRoot}"
                  BorderBrush="White"
                  CornerRadius="0,3,3,3"
                  Padding="{Binding PopupPadding,
                                    ElementName=userControlRoot}"&gt;
  
              &lt;ContentPresenter Content="{Binding PopupContentHolder, ElementName=userControlRoot}" /&gt;
          &lt;/Border&gt;
      &lt;/Popup&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have simplified the control but the problem reproduces with that version too. The code behind for the control mostly contains  dependency properties, the only logic is shown below</p>
  
  <pre><code>public partial class PopupButton : UserControl
  {
      //... dependency properties
  
      public PopupButton()
      {
          InitializeComponent();
      }
  
      private void btn_Click(object sender, RoutedEventArgs e)
      {
              Storyboard s = (Storyboard)TryFindResource("PopupOpenStoryBoard");
              s.Begin();
      }
  
      private void popup_PreviewMouseDown(object sender, MouseButtonEventArgs e)
      {
          //trick to close popup when the button inside is clicked
          //this must be done with storyboard and delay
          //since popup can not be closed before the event reaches clicked
          //button
          if (e.Source is Button)
          {
              Storyboard s = (Storyboard)TryFindResource("PopupCloseStoryBoard");
              s.Begin();
          }
      }
  }
  </code></pre>
  
  <p>Has anyone any clue what can be wrong with it?
  Thanks.</p>