Trigger doesn't fire when overriding triggers in a ControlTemplate

May 13 2010 10:14 AM

Hello. I've created a ControlTemplate to apply a general style to all the buttons in the LayoutRoute. I've also applied Triggers for the 'IsPressed' property so that a Storyboard fires on the event. I am new to XAML and noticed that applying these triggers must have overrided the OnMouseUp triggers for each individual button. How do I create a trigger that applies to all the buttons that raises the C# procedure void buttonClick. From within this procedure I will identify which button has been clicked. Thanks!!! Code follows:
<Style TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
     <ControlTemplate TargetType="{x:Type Button}">
         <ControlTemplate.Resources>
             <Storyboard x:Key="MouseDownAnimation">
                 <ColorAnimation Storyboard.TargetName="ButtonBorderGradientStop1" Storyboard.TargetProperty="Color" To="#FF2D0100" Duration="0:0:0.1" />
                 <ColorAnimation Storyboard.TargetName="ButtonBorderGradientStop2" Storyboard.TargetProperty="Color" To="#FF680300" Duration="0:0:0.1" />
             </Storyboard>
             <Storyboard x:Key="MouseUpAnimation">
                 <ColorAnimation Storyboard.TargetName="ButtonBorderGradientStop1" Storyboard.TargetProperty="Color" To="#FF680300" Duration="0:0:0.1" />
                 <ColorAnimation Storyboard.TargetName="ButtonBorderGradientStop2" Storyboard.TargetProperty="Color" To="#FF2D0100" Duration="0:0:0.1" />
             </Storyboard>
         </ControlTemplate.Resources>
     
         <Border x:Name="ButtonBorder" CornerRadius="9,9,9,9" SnapsToDevicePixels="True" BorderBrush="#FF323232" BorderThickness="3" Width="125" Height="25">
             <Border.Background>
                 <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                     <GradientBrush.GradientStops>
                         <GradientStop x:Name="ButtonBorderGradientStop1" Color="#FF680300" Offset="0.0" />
                         <GradientStop x:Name="ButtonBorderGradientStop2" Color="#FF2D0100" Offset="1.0" />
                     </GradientBrush.GradientStops>
                 </LinearGradientBrush>
             </Border.Background>
       <ContentPresenter x:Name="Contents" HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Margin="2,1,2,2"/>
         </Border>
      
         <ControlTemplate.Triggers>
             <Trigger Property="IsPressed" Value="True">
        <Trigger.EnterActions>
                     <BeginStoryboard Storyboard="{StaticResource MouseDownAnimation}" />
        </Trigger.EnterActions>
                 <Trigger.ExitActions>
                     <BeginStoryboard Storyboard="{StaticResource MouseUpAnimation}" />
                 </Trigger.ExitActions>
             </Trigger>
         </ControlTemplate.Triggers> 
     </ControlTemplate>
     
    </Setter.Value>
            </Setter>
        </Style>
 
 
private void buttonClick(object sender, MouseButtonEventArgs e)
{
   switch ((sender as Button).Name)
{
   case "btnResetWorksheet":
{
   break;
}
   case "btnHelp":
{
   break;
}
   case "btnEmployerReport":
{
   break;
}