Reputation: 25
After animating my three slider values to 100
, 50
, and 20
, I can't change the values back to 1
. A reset button is coded to set them to 1
but they stay at 100
, 50
, and 20
!
Here's the code:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation sld_1anim = new DoubleAnimation(100, TimeSpan.FromMilliseconds(1000));
sld_1.BeginAnimation(Slider.ValueProperty, sld_1anim);
DoubleAnimation sld_2anim = new DoubleAnimation(50, TimeSpan.FromMilliseconds(1000));
sld_2.BeginAnimation(Slider.ValueProperty, sld_2anim);
DoubleAnimation sld_3anim = new DoubleAnimation(20, TimeSpan.FromMilliseconds(1000));
sld_3.BeginAnimation(Slider.ValueProperty, sld_3anim);
}
private void Button_Click_1(object sender, RoutedEventArgs e) /// reset button NOT WORKS
{
sld_1.Value = 1;
sld_2.Value = 1;
sld_3.Value = 1;
MessageBox.Show(sld_1.Value.ToString());
MessageBox.Show(sld_2.Value.ToString());
MessageBox.Show(sld_3.Value.ToString());
}
}
Upvotes: 0
Views: 154
Reputation: 61339
The default FillBehavior
is HoldEnd
which means your animation is going to hold it on that last value.
Pass FillBehavior.Stop
as the third parameter to your animations.
new DoubleAnimation(20, TimeSpan.FromMilliseconds(1000), FillBehavior.Stop)
As an aside; I would recommend just using a storyboard in XAML unless those numbers are going to become variable.
Upvotes: 1