Storyboard.Gettarget返回的结果是Null

时间:2012-04-09 22:26:05

标签: wpf storyboard

DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 400;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
Storyboard.SetTargetName(da, "r13");
Storyboard.SetTargetProperty(da, new PropertyPath(Canvas.LeftProperty));
mySubStoryBoard.Children.Add(da);
DependencyObject do =Storyboard.GetTarget(mySubStoryBoard.Children[0]);
string str = Storyboard.GetTargetName(mySubStoryBoard.Children[0]);

结果:do == null,str == r13。

为什么?帮助我,谢谢。

1 个答案:

答案 0 :(得分:0)

你期待什么?您设置了Storyboard.SetTargetName MethodStoryboard.SetTargetProperty Method,但未设置Storyboard.SetTarget Method

这就是Storyboard.GetTarget Method返回null的原因。