Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello.
I need example how to do programmatically color animation for a grid control. Just change background color 1 to color 2.

Example http://blogs.msdn.com/b/silverlight_sdk/archive/2008/03/24/create-an-animation-in-code.aspx[^]
Thank you.
Posted
Comments
Richard MacCutchan 26-Sep-14 12:38pm    
The link you posted is an example.
Style-7 26-Sep-14 14:17pm    
The type of animation is not the same.

1 solution

//XAML code

XML
<Grid x:Name="btn_2" MouseLeftButtonDown="MouseLeftButtonDown_Button">

    <Grid.Background>
        <SolidColorBrush />
    </Grid.Background>

    <TextBlock x:Name="btn_2_tb" Text="2" TextAlignment="Center" Foreground="Black"></TextBlock>
</Grid>




//C# code
ColorAnimation ca = new ColorAnimation();
ca.Duration = new Duration(TimeSpan.FromSeconds(1));
ca.From = Color.FromArgb(255, 255, 0, 0);
ca.To = Color.FromArgb(255, 0, 0, 255);

Storyboard.SetTarget(ca, btn_0 );

Storyboard.SetTargetProperty(ca, new PropertyPath("UIElement.Background.Color"));
// alternative tested PropertyPath
// "Panel.Background.Color"
// "Panel.Background.SolidColorBrush.Color"
// "(Panel.Background).(SolidColorBrush.Color)"

Storyboard sb = new Storyboard();
sb.Children.Add(ca);
sb.Begin();
 
Share this answer
 

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