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

  • Home
  • SEARCH
  • 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 3406070
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:34:59+00:00 2026-05-18T05:34:59+00:00

In a Windows Phone 7 project, I’m doing a color animation on a button

  • 0

In a Windows Phone 7 project, I’m doing a color animation on a button background, changing the color through a range. I want the animation to stop when the button is clicked, and have the button’s background color stay on the color it had when it was clicked. To this end, I have the following set:

<Button Height="72" HorizontalAlignment="Left" 
    Margin="135,48,0,0" Name="button1" VerticalAlignment="Top" Width="160" 
    Click="button1_Click">
    <Button.Resources>
        <Storyboard x:Name="colorStoryboard">
        <!-- Animate the background color of the canvas from red to green over 4 seconds. -->
        <ColorAnimation BeginTime="00:00:00" Storyboard.TargetName="button1" 
            Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)"
            From="Red" To="Blue" Duration="0:0:4" />
        </Storyboard>
    </Button.Resources>
</Button>

The click event is coded as:

private void button1_Click(object sender, RoutedEventArgs e)
{
    colorStoryboard.Pause();
    Brush holdBrush = new SolidColorBrush();
    holdBrush = button1.Background;
    colorStoryboard.Stop();
    button1.Background = holdBrush;
}

This is how I think it would work: after the storyboard.Pause() stops any further change in the color (the Stop method causes the button to go back to its default background color), I am saving the Background’s current Brush into the new Brush holdBrush, and then after doing the Stop() I attempt to restore the button’s background property to the value it had when the Pause occurred, using holdBrush.

This isn’t what is happening, however. In the code above I’ve confirmed that holdBrush has the color that the button had when the storyboard paused, but after Stop occurs, holdBrush now has the default color — actually, it has the color #FFFFFF, which is the color the button takes on when it is clicked. Any ideas, anyone?

  • 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-18T05:35:00+00:00Added an answer on May 18, 2026 at 5:35 am

    Animation in Silverlight for Windows Phone are run by Compositor Thread and what you do is just a reference copy of Background object (shallow copy) and the value is shared between UI Thread and Compositor Thread. To get the value of color you need to get the value of a DependencyProperty

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            colorStoryboard.Pause();
            var color = button1.Background.GetValue(SolidColorBrush.ColorProperty); 
            colorStoryboard.Stop();
            Dispatcher.BeginInvoke( () => button1.Background.SetValue(SolidColorBrush.ColorProperty,color)); 
        }
    

    But this approach is not the best for Silverlight. I would restyle the default template of the button(Visual State).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a Windows Phone 7 project, and is retrieving personal details for
Hey, im doing a little app for my smart phone, using Windows Mobile 6.
I am trying to use WpfToolkit DataGrid in Windows Phone 7 project (Silverligt 4)
In a Windows Phone 7 Silverlight project, I had a service reference to a
I had a unit test project for my windows phone 7 app ViewModels using
Did someone try to convert a windows phone 7 project written in c# to
I'm working on a windows phone 7 project, with silverlight, and i'm trying to
I'm trying to use RestSharp ( http://restsharp.org/ ) in a Windows Phone 7 project,
I have a simple Silverlight app that I want to run on Windows Phone
A Windows Phone application referencing a dll(another class library project). There is an asynchronous

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.