Storyboard.SetTargetProperty設置一個動畫目標屬性,但下面一行中的Storyboard.GetTargetProperty將返回null。如何獲得動態創建的故事板的目標屬性?我的代碼只返回null
以下代碼在倒數第二行崩潰, Storybard.SetTargetProperty(a,Storyboard.GetTargetProperty(a));在DoubleAnimation a之後已經分配了一個目標屬性的 。任何幫助將不勝感激!
刪除該行會生成一個可正確動畫矩形的故事板。
完整的代碼是在這裏:
例如,
public Storyboard moveDown(Rectangle rect){
//Set up the animation
DoubleAnimation a=new DoubleAnimation();
a.RepeatBehavior=new RepeatBehavior(1);
a.FillBehavior=FillBehavior.HoldEnd;
a.From=0;
a.To=100;
a.Duration=10;
//Set up the Storyboard
Storyboard sb=new Storyboard();
sb.Children.Add(a);
sb.Duration=a.Duration;
//Assign animation's target and property. This resulting animation works great.
Storyboard.SetTarget(a, rect);
Storyboard.SetTargetProperty(a, new PropertyPath(Canvas.TopProperty));
//Here's the problem: I can't get the propertypath back with GetTargetProperty
//targetProperty is null.
var targetProperty=Storyboard.GetTargetProperty(a);
//And this line crashes the program. It's only here for debugging purposes.
Storyboard.SetTargetProperty(a, Storyboard.GetTargetProperty(a));
//You need to say canvas.Resources.Add("a unique id in quotes", sb) if you want it to
//run on a canvas.
return sb;
任何幫助將非常感激。
只是在黑暗中隨機拍攝,但這樣做的工作? 'Storyboard.SetTargetProperty(a,new PropertyPath(「(Canvas.TopProperty)」));' – keyboardP 2011-06-04 18:53:26