Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:04:40+00:00 2026-05-26T15:04:40+00:00

How can I programatically change the Color of a Rectangle in my Grid? ColorAnimation

  • 0

How can I programatically change the Color of a Rectangle in my Grid?

        ColorAnimation myColorAnimation = new ColorAnimation();
        myColorAnimation.From = Colors.Red;
        myColorAnimation.To = Colors.Blue;
        myColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
        myColorAnimation.AutoReverse = false;

        myStoryboard = new Storyboard();
        myStoryboard.Children.Add(myColorAnimation);
        Storyboard.SetTargetName(myColorAnimation, ?); // What do I put here
        Storyboard.SetTargetProperty(myColorAnimation, new PropertyPath //What do I put here?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:04:41+00:00Added an answer on May 26, 2026 at 3:04 pm

    OK, I found a way to do this:

    I create a StoryBoard for each Grid item:

        List<Storyboard> _animatableGridRectToGray = new List<Storyboard>();
        List<Storyboard> _animatableGridRectToWhite = new List<Storyboard>();
    

    and populate:

    private void initAnimatableGridRectangles()
    {
        int index = 1;
        foreach (Rectangle rect in SequenceGrid.Children)
        {
            SolidColorBrush tempBrush = new SolidColorBrush();
            rect.Fill = tempBrush;
            string brushName = "Brush" + index;
            _gridBrushes.Add(brushName, tempBrush);
            this.RegisterName(brushName, tempBrush);
    
            Storyboard tempSBToGray = new Storyboard();
            Storyboard tempSBToWhite = new Storyboard();
            ColorAnimation tempColAnimToGray = getAnimToGray();
            ColorAnimation tempColAnimToWhite = getAnimToWhite();
            tempSBToGray.Children.Add(tempColAnimToGray);
            tempSBToWhite.Children.Add(tempColAnimToWhite);
            Storyboard.SetTargetName(tempColAnimToGray, brushName);
            Storyboard.SetTargetName(tempColAnimToWhite, brushName);
            Storyboard.SetTargetProperty(tempColAnimToGray, new PropertyPath(SolidColorBrush.ColorProperty));
            Storyboard.SetTargetProperty(tempColAnimToWhite, new PropertyPath(SolidColorBrush.ColorProperty));
            _animatableGridRectToGray.Add(tempSBToGray);
            _animatableGridRectToWhite.Add(tempSBToWhite);
            index++;
        }
    }
    
    
    private ColorAnimation getAnimToGray()
    {
        ColorAnimation colAnim = new ColorAnimation();
        colAnim.To = Colors.Gray;
        colAnim.Duration = new Duration(TimeSpan.FromMilliseconds(500));
        colAnim.AutoReverse = false;
        return colAnim;
    }
    
    private ColorAnimation getAnimToWhite()
    {
        ColorAnimation colAnim = new ColorAnimation();
        colAnim.To = Colors.White;
        colAnim.Duration = new Duration(TimeSpan.FromMilliseconds(500));
        colAnim.AutoReverse = false;
        return colAnim;
    }
    

    Then I can animate like so:

    _animatableGridRectToGray[index].Begin(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we change the keyboard language in iPhone from English to Japanese programatically?
How can I change the fore color of the error message programatically? RegularExpressionValidator errorExp
How can I programatically remove the readonly attribute from a directory in C#?
How can I programatically change the backgroundColor of an UITextField that sits in a
Looking at the highlight JQuery effect: http://docs.jquery.com/UI/Effects/Highlight You can change the background color of
How can I change the background and foreground colors of a WPF Textbox programmatically
I'm using UITableViewCell. I'd like to programatically change the UITableViewCell's mode from Delete to
How can I change EditText's cursor's color programmatically ? In android 4.0 and above,
Can I programatically change the quality of a PDF? I have a client that
How can I programmatically change the back color of a single cell in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.