2013-03-23 104 views
0

我有以下類:DoubleAnimation是不更新的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每次都會上升。但事實並非如此。

任何想法爲什麼?

回答

0

你故事板的持續時間應該是一天嗎?我認爲這需要一段時間,直到第一次改變發生。或者我想念這裏的東西......?

+0

在一秒鐘內它應該改變大約0.0001,所以如果它能工作,我會看到這個改變 – Dzior 2013-03-25 06:31:36

相關問題