繁体   English   中英

DoubleAnimation不会更新DependencyProperty

[英]DoubleAnimation does not update DependencyProperty

我有以下课程:

public class BindableClock : DependencyObject, INotifyPropertyChanged
{
    private DoubleAnimation animation = new DoubleAnimation
    {
        From = 0.0d,
        To = 10.0d,
        Duration = new Duration(TimeSpan.FromDays(1d)),
        BeginTime = TimeSpan.Zero
    };
    private Storyboard storyboard = new Storyboard { Duration = Duration.Automatic };


    public double BogusDouble
    {
        get { return (double)GetValue(BogusDoubleProperty); }
        set { SetValue(BogusDoubleProperty, value); }
    }

    // Using a DependencyProperty as the backing store for BogusDouble.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty BogusDoubleProperty =
        DependencyProperty.Register("BogusDouble", typeof(double), typeof(BindableClock), new PropertyMetadata(0.0d, BogusDoubleChangedCallback));

    public static void BogusDoubleChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var clock = d as BindableClock;
        clock.TimeSpan = clock.storyboard.GetCurrentTime();
    }


    public TimeSpan TimeSpan {get; set;}

    public BindableClock(bool start)
    {
        Storyboard.SetTarget(animation, this);
        Storyboard.SetTargetProperty(animation, "BogusDouble");
        storyboard.Children.Add(animation);
        Value = TimeSpan.ToString(Format);
        if (start)
            storyboard.Begin();
    }

    public void Begin()
    {
        storyboard.Begin();
    }

    public void Stop()
    {
        storyboard.Stop();
    }
}

我期望在运行Begin()方法之后, BogusDouble属性将被更新几次,并且BogusDoubleChangedCallback都会被升高。 但事实并非如此。

知道为什么吗?

故事板的持续时间应该是一天? 我认为这将需要一些时间才能进行第一次更改。 还是我想念这里的东西...?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM