Saturday, May 3, 2014

Animantion with use of DoubleAnimantion in WPF

use of doubleanimation of opacity property

with XAML file


<Button Height="23" Margin="102,95,100,0" Name="button3" VerticalAlignment="Top" Content="Opacity">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="button3"
                                             Storyboard.TargetProperty="Opacity"
                                             From="1"
                                             To="0"
                                             Duration="0:0:2"
                                             AutoReverse="True"
                                             RepeatBehavior="3x"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>





With xaml.cs file

Change the button color with animation

write this code on button click event......

SolidColorBrush myBrush = new SolidColorBrush();
            myBrush.Color = Colors.Blue;
            ColorAnimation ca = new ColorAnimation();
            ca.From = Colors.Red;
            ca.To = Colors.Blue;
            ca.Duration = new Duration(TimeSpan.FromMilliseconds(2000));
            ca.AutoReverse = true;
            ca.RepeatBehavior = RepeatBehavior.Forever;
            myBrush.BeginAnimation(SolidColorBrush.ColorProperty, ca);
            Button1.Background = myBrush;

No comments:

Post a Comment