请在visual basic中提供答案。
只想知道Storyboard.SetTargetName
的语法。
Me._StoryMoveLeft = New Storyboard
DAnim = New DoubleAnimation
Me._StoryMoveLeft.Children.Add(DAnim)
Storyboard.SetTargetName(DAnim, "SmoothRectTranslate")
Storyboard.SetTargetProperty(DAnim, New PropertyPath(TranslateTransform.XProperty))
Me._StoryMoveLeft.Stop()
danim = CType(Me._StoryMoveLeft.Children(0), DoubleAnimation)
DAnim.Duration = New Duration(ts)
DAnim.To = newDestinationRect.Left
Me._StoryMoveLeft.Begin() '<-- ERROR OCCOURS Cannot resolve TargetName SmoothRectTranslate.
<Rectangle x:Name="RectSmoot" Fill="Lime" Width="20" Height="20" Stroke="{Binding Stroke}" StrokeThickness="{Binding StrokeThickness}" HorizontalAlignment="Left" VerticalAlignment="Top" >
<Rectangle.RenderTransform>
<TranslateTransform X="20" Y="20" x:Name="SmoothRectTranslate" />
</Rectangle.RenderTransform>
</Rectangle>
答案 0 :(得分:0)
要在代码中使用Storyboard.TargetName
,您需要创建一个NameScope,请参阅documentation of SetTargetName
以获取如何执行此操作的示例。
(顺便说一句,如果你只有一个动画我根本不会使用故事板,那只会带来麻烦,只需在变换上调用BeginAnimation
)