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

Thank you.
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

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

        <SolidColorBrush />

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

//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();
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