Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF Threading Animation
Hi Community,
 
I've created a ControlTemplate in my Application.Resources.
I'm using this Template for Buttons to make their Background transparent.
 
<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
<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
<EventTrigger RoutedEvent="Button.Click">
   <BeginStoryboard Storyboard="{StaticResource HollowButtonGlow}"/>
</EventTrigger>
 

<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
<Button x:Name="btHollow" Template="{StaticResource HollowButtonTemplate}">
    HollowButtonContent
</Button>
 
And it works fine Smile | :)
 
But if i put some code in my ClickEvent-Handler ...
<Button x:Name="btHollow" Click="btHollow_Click" Template="{StaticResource HollowButtonTemplate}">
    HollowButtonContent
</Button>
 
private void btHollow_Click(object sender, RoutedEventArgs e)
   {
      //Some Code
   }
 
...the animation starts after the code is finished Frown | :(
 

Is there a common way to make a click-Animation without using a seperate Thread for the ClickEvent-Handler-Code ?
Posted 21-Jul-11 22:09pm
Edited 21-Jul-11 22:16pm
v2
Comments
Mark Salsbery at 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)

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 22 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100