在代码隐藏中设置动画后,无法重置滑块值

时间:2018-05-25 18:38:44

标签: c# wpf

将我的三个滑块值设置为1005020后,我无法将值更改回1。对重置按钮进行编码以将其设置为1,但它们保持在1005020

以下是代码:

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());
    }
}

1 个答案:

答案 0 :(得分:1)

默认FillBehavior-ltcmalloc,这意味着您的动画会将其保留在最后一个值上。

HoldEnd作为动画的第三个参数传递。

FillBehavior.Stop

撇开;我建议只在XAML中使用故事板,除非这些数字变得可变。