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

Hello,

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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1" Loaded="UserControl_Loaded">
    <Grid>
        <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">
            <Popup.Style>
                <Style TargetType="{x:Type Popup}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=PART_TextBox, Path=IsFocused}" Value="True">
                            <Setter Property="IsOpen" Value="True" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Popup.Style>
            <Button x:Name="PopupButton" FontSize="12" Content="Click Me" Click="PopupButton_Click">
                <Button.ContextMenu>
                    <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>
                    </ContextMenu>
                </Button.ContextMenu>
            </Button >
        </Popup>
    </Grid>
</UserControl>