无法解决TargetName错误

时间:2011-09-03 10:12:16

标签: wpf vb.net

请在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>

1 个答案:

答案 0 :(得分:0)

要在代码中使用Storyboard.TargetName,您需要创建一个NameScope,请参阅documentation of SetTargetName以获取如何执行此操作的示例。

(顺便说一句,如果你只有一个动画我根本不会使用故事板,那只会带来麻烦,只需在变换上调用BeginAnimation