我有一个Textblock动画,如果它在画布中,它可以单独运行,但如果我将画布放在Grid中,它就无法工作。它可以使它工作/工作吗?我错过了什么使它成功?
<Grid Width="3200" Height="99">
<Canvas Height="70" Width="3200" Margin="-900,0,0,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="States">
<VisualState x:Name="Left">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="myTextBlock" Storyboard.TargetProperty="(Canvas.Left)" To="-100" Duration="0:0:2" From="1500" RepeatBehavior="Forever"/>
</Storyboard>
<VisualState.StateTriggers>
<StateTrigger x:Name="desplazamiento" IsActive="true"/>
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!-- Offset the text using a TranslateTransform. -->
<TextBlock x:Name="myTextBlock" Text="Text going throught animation" VerticalAlignment="Bottom" Margin="0,-20,0,0" TextWrapping="Wrap" FontSize="33" Canvas.Top="36" />
</Canvas>
</Grid>
如果删除Grid标签,它确实有效。
答案 0 :(得分:2)
VisualStateManager
只影响内部元素,应该在第一个网格内部控制之后放置。试试这个:
<Grid Width="3200" Height="99">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="States">
<VisualState x:Name="Left">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="myTextBlock" Storyboard.TargetProperty="(Canvas.Left)" To="-100" Duration="0:0:2" From="1500" RepeatBehavior="Forever"/>
</Storyboard>
<VisualState.StateTriggers>
<StateTrigger x:Name="desplazamiento" IsActive="true"/>
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Canvas Height="70" Width="3200" Margin="-900,0,0,0">
<!-- Offset the text using a TranslateTransform. -->
<TextBlock x:Name="myTextBlock" Text="Text going throught animation" VerticalAlignment="Bottom" Margin="0,-20,0,0" TextWrapping="Wrap" FontSize="33" Canvas.Top="36" />
</Canvas>
</Grid>