tags:

views:

44

answers:

1

i used this code to animation my window

        winLogin login = new winLogin();
        login.Owner = this;
        login.Show();

        DoubleAnimation da = new DoubleAnimation();
        da.From = 0;
        da.To = this.Left + ((this.Width - login.Width) / 2);
        da.AutoReverse = false;
        da.Duration = new Duration(TimeSpan.FromSeconds(0.1));
        login.BeginAnimation(Window.LeftProperty, da);

problem is that whenever i set the left property of this window(after the animation), it goes crazy..

i used this code to align the child windows to be always on the center bu the left property of the windows on which i used an animation cannot be properly changed.

private void Window_LocationChanged(object sender, EventArgs e) { foreach (Window win in this.OwnedWindows) { win.Top = this.Top + ((this.Height - win.Height) / 2); win.Left = this.Left + ((this.Width - win.Width) / 2); } }

A: 

First of all, when you set an animation you should always remove the potential previous animation of that property:

login.BeginAnimation(Window.LeftProperty, null);
login.BeginAnimation(Window.LeftProperty, da);

If you don't so this you will get a memory leak and probably some other undesired behavior.

Also due to the DependencyProperty precedence you can not set a value on a DependecyProperty that has an active animation, wich is the case in your animation because its FillBehavior is set to HoldEnd (the default). Again you would have to remove the animation first.

bitbonk
Actually wouldn't it be alright to set the value with SetCurrentValue? NVM, of course the animation will still have precedence with HoldEnd.
Alex Paven
The new .NET 4 DependencyObject.SetCurrentValue is used to set the value on databound DependencyProperties without affecting the databound source value. Your Window.LeftProperty however is not databound. Animations set the property directly.
bitbonk