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 3398090
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:36:27+00:00 2026-05-18T04:36:27+00:00

I am animating some property using DoubleAnimation . Before animation is triggered any local

  • 0

I am animating some property using DoubleAnimation. Before animation is triggered any local or Setter changes are properly reflected in the property. After animation completes nothing seems to be able to change the value of the property. I have even tried ClearValue and InvalidateProperty as well set calling SetValue but the value leftover from animation persists. If animation is repeated, the property continues to be animated as expected so it only appears to be locked for non-animation changes.

Is there a way to rectify this behavior? I want to use the animation to change the property value but still be able to change it manually or via a Setter to anything else. I know a thing or two about Dependency Property Value Precedence but the behavior I am currently experiencing is a bit strange. I’d hate to have to use “manual animations”.

EDIT: Added sample XAML + code.

<Window x:Class="WpfApplication7.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300"
        x:Name="_this"
        Background="Red">
    <DockPanel>
        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center" >
            <Button Click="ToggleOnClick">Toggle!</Button>
            <Button Click="SetHalfOnClick">Set to 0.5!</Button>
        </StackPanel>
        <TextBox DockPanel.Dock="Bottom" IsReadOnly="True" Text="{Binding ElementName=_viewbox,Path=Opacity}" />
        <Viewbox x:Name="_viewbox">
            <Viewbox.Style>
                <Style TargetType="{x:Type FrameworkElement}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=IsToggled,ElementName=_this,Mode=OneWay}" Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation To="0.2"
                                                 Duration="0:0:0.5"
                                                 Storyboard.TargetProperty="(UIElement.Opacity)" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation To="1"
                                                 Duration="0:0:0.5"
                                                 Storyboard.TargetProperty="(UIElement.Opacity)" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Viewbox.Style>

            <TextBlock Text="Sample!" />
        </Viewbox>
    </DockPanel>
</Window>

Here is the code:

using System.Windows;

namespace WpfApplication7
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1
    {
        public bool IsToggled
        {
            get { return (bool)GetValue(IsToggledProperty); }
            set { SetValue(IsToggledProperty, value); }
        }

        public static readonly DependencyProperty IsToggledProperty = DependencyProperty.Register("IsToggled", typeof(bool), typeof(Window1), new UIPropertyMetadata(false));

        public Window1()
        {
            InitializeComponent();
        }

        private void ToggleOnClick(object sender, RoutedEventArgs e)
        {
            IsToggled = !IsToggled;
        }

        private void SetHalfOnClick(object sender, RoutedEventArgs e)
        {
            _viewbox.Opacity = 0.5;
        }
    }
}
  • 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-18T04:36:27+00:00Added an answer on May 18, 2026 at 4:36 am

    Edit 2 in response to comments:

    In your example you can work around the problem by:

    1. Setting FillBehaviour to Stop on the animation
    2. Adding a handler in code to the Completed event:

    <Storyboard Completed="FadeOut_Completed">

    Finally, set the desired ‘final’ value in the Completed handler (either explicitly or by using the current value of the property

    private void FadeOut_Completed(object sender, EventArgs e)
    {
       _viewbox.Opacity = _viewbox.Opacity; //this sets the DP value to the animated value
    }
    

    This works in your sample; hopefully it will work in your problem!


    Original Answer

    If you set the FillBehaviour property of the Storyboard to Stop (instead of the default value of HoldEnd) it will revert to the pre-animation value of the property once the animation completes. HoldEnd causes the animation to maintain its final value on the property

    Update in response to comments:

    As noted in the comments, the animation value will override the value set against the property when HoldEnd is specified as the FillBehaviour.

    This makes it slightly tricky to set the value to something else.

    I am not sure if there is a better way to achieve this, but the example below shows one way to work around it. Its hard to judge how applicable this is without a sample usage from the OP, but in this example I am animating the width of a Rectangle on load, and then resetting it to another value when a button is clicked:

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Triggers>
            <EventTrigger RoutedEvent="Window.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="Target" Storyboard.TargetProperty="Width"
                                         From="10" To="100" Duration="0:00:01" FillBehavior="HoldEnd" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Window.Triggers>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Rectangle Height="10" Width="10" Fill="Red"  x:Name="Target"/>
            <Button Grid.Row="1" Content="Resize">
                <Button.Triggers>
                    <EventTrigger RoutedEvent="Button.Click">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Target" Storyboard.TargetProperty="Width">
                                    <DiscreteDoubleKeyFrame Value="50" KeyTime="0:00:00" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Button.Triggers>
            </Button>
        </Grid>
    </Window>
    

    This works because the new animation overrides the value set in the original.

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

Sidebar

Related Questions

I am using slideDown animation to show some divs in a newly added table
I'm animating a UIView's frame property using a CAKeyframeAnimation on the view's CALayer and
Is there an animation format supported in Qt (using v4.4) that will support a
What is a good way to perform animation using .NET? I would prefer not
Is there a preferred way to handle animation when using Flex -- For instance,
I am having some trouble getting my application to properly resize the text of
I'm having some minor problems with some animations I'm trying to set up. I
I need to get some AVI animations for use with the Borland VCL TAnimate
I have a storyboard(1) that does some basic animations in 2 seconds. I want
I have an animation and I want it to play it just only once.

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.