Reputation: 129
I am creating a new Custom Button everything works fine. I am using Storyboard for animation, and the storyboard contains the MouseEnter, MouseLeave, MouseDoun, MouseUp events. After introducing Click event MouseDown event stops working, followed by MouseUp The XAML code of the CustomButton is .....
<Style TargetType="{x:Type local:FlatButton}">
<Setter Property="Focusable" Value="False" />
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:FlatButton}">
<Grid>
<Rectangle Name="Part_Rectangle" Fill="{Binding Path=Background}"/>
<Label Name="Part_Label" Foreground="White" FontSize="{Binding FontSize, FallbackValue='9'}"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Style="{StaticResource StyleGray}"
Content="{Binding Path=Caption, RelativeSource={RelativeSource TemplatedParent}}"
FontFamily="{Binding Path=FontFamily, RelativeSource={RelativeSource TemplatedParent}}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The Style for the label is.....
<Style x:Key="StyleGray" TargetType="Label">
<Setter Property="Background" Value="#00000000"/>
<Style.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Label.Background).(SolidColorBrush.Color)"
To="#26000000" Duration="0:0:0.15"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Label.Background).(SolidColorBrush.Color)"
To="#00000000" Duration="0:0:0.15"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseDown">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Label.Background).(SolidColorBrush.Color)"
To="#3F000000" Duration="0:0:0.15"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseUp">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Label.Background).(SolidColorBrush.Color)"
To="#26000000" Duration="0:0:0.15"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
And the Implementation of the button is ...
<local:FlatButton Grid.Column="8" x:Name="CloseButton" Caption=""
Height="30" Width="45" FontSize="10"
ButtonStyle="{StaticResource StyleRed}"/>
And the Code Behind is ...
void CloseBtn_Click(object sender, RoutedEventArgs e)
{
Window window = this.TemplatedParent as Window;
if (window != null)
{
window.Close();
}
}
Plese, tell me what I am doing wrong.
Upvotes: 1
Views: 251
Reputation: 392
I'm posting this as an answer because I cannot comment. By looking at your code, I think that the problem may be related to the RountedEvents handling from the button itself.
Try to run the storyboards of the label inside the button ControlTemplate Triggers, instead of using a style for the label, targetting the button events instead of the label events.
Upvotes: 1