UserControl with Button Inside Popup not getting Click Events when added to DataGridTemplateColumn

Jul 21, 2009 at 4:56 PM
Edited Jul 21, 2009 at 4:57 PM


I have a UserControl that I add to the CellTemplate of a DataGridTemplateColumn.  Inside this UserControl is a Textbox that when it is focused displays a Popup control with a Button.  When I click this Button my UserControl doesn't receive the Click event.  Anyone have any thougths?  There really isn't anything special about how the UserControl is added to the CellTemplate, and I have provided the UserControl Code below:

<UserControl x:Class="WpfApplication1.UserControl1"
    xmlns:local="clr-namespace:WpfApplication1" Loaded="UserControl_Loaded">
        <TextBox x:Name="PART_TextBox" BorderThickness="0" VerticalAlignment="Center" Background="Transparent"/>
        <Popup AllowsTransparency="True" PopupAnimation="Fade"  PlacementTarget="{Binding ElementName=PART_TextBox}" Placement="Right" HorizontalOffset="2" VerticalOffset="14">
                <Style TargetType="{x:Type Popup}">
                        <DataTrigger Binding="{Binding ElementName=PART_TextBox, Path=IsFocused}" Value="True">
                            <Setter Property="IsOpen" Value="True" />
            <Button x:Name="PopupButton" FontSize="12" Content="Click Me" Click="PopupButton_Click">
                    <ContextMenu x:Name="ButtonContextMenu" PlacementTarget="{Binding ElementName=PopupButton}">
                        <MenuItem Header="Replicate Data"></MenuItem>
                        <MenuItem Header="Cut"></MenuItem>
                        <MenuItem Header="Copy"></MenuItem>
                        <MenuItem Header="Paste"></MenuItem>
            </Button >