Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Community,

I've created a ControlTemplate in my Application.Resources.
I'm using this Template for Buttons to make their Background transparent.

XML
<ControlTemplate TargetType="Button" x:Key="HollowButtonTemplate">
    <Border x:Name="bord" Background="#00000000">
        <ContentPresenter Content="{TemplateBinding Content}" 
       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    </Border>
    <ControlTemplate.Triggers[...]>
</ControlTemplate>


There are two Triggers.

One to make a hover-effect and another to make my button glowing.

Hover-Effect
XML
<Trigger Property="IsMouseOver" Value="True">
   <Setter Property="Effect">
      <Setter.Value>
        <DropShadowEffect Direction="255" BlurRadius="3" 
           ShadowDepth="1" Color="Black"/>
      </Setter.Value>
   </Setter>
</Trigger>


Glow-Effect
XML
<EventTrigger RoutedEvent="Button.Click">
   <BeginStoryboard Storyboard="{StaticResource HollowButtonGlow}"/>
</EventTrigger>



MSIL
<Storyboard x:Key="HollowButtonGlow">
   <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Effect).Color">
      <SplineColorKeyFrame KeyTime="0:0:0.0" Value="White" />
      <SplineColorKeyFrame KeyTime="0:0:0.4" Value="Black" />
   </ColorAnimationUsingKeyFrames>
</Storyboard>


Now Adding the Template to my Button
XML
<Button x:Name="btHollow" Template="{StaticResource HollowButtonTemplate}">
    HollowButtonContent
</Button>


And it works fine :)

But if i put some code in my ClickEvent-Handler ...
XML
<Button x:Name="btHollow" Click="btHollow_Click" Template="{StaticResource HollowButtonTemplate}">
    HollowButtonContent
</Button>


C#
private void btHollow_Click(object sender, RoutedEventArgs e)
   {
      //Some Code
   }


...the animation starts after the code is finished :(


Is there a common way to make a click-Animation without using a seperate Thread for the ClickEvent-Handler-Code ?
Posted
Updated 21-Jul-11 21:16pm
v2
Comments
Mark Salsbery 22-Jul-11 16:33pm    
You must be tying up the UI thread, so even starting the animation manually may not help. Lengthy operations should be done on a separate thread!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900