我有一个自定义控件,我想控制其动画。我尝试使用它来更新它,VisualStateManager.GoToState
但它总是false
在 Silverlight 中返回,并且动画永远不会开始。尽管使用相同的 XAML,但这在 WPF 中完美运行。
Silverlight 代码
//to start
retval = ExtendedVisualStateManager.GoToElementState(this.canvasParent, "WorkingState", true);
WPF 代码
retval = VisualStateManager.GoToElementState(this.canvasParent, "WorkingState", true);
XAML(通用):
<Style TargetType="local:WaitSpinner">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:WaitSpinner">
<Viewbox Visibility="{TemplateBinding Visibility}">
<Canvas RenderTransformOrigin="0.5,0.5" x:Name="CanvasParent" Width="120" Height="120">
<!-- other awesomeness -->
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="Working">
<VisualState x:Name="WorkingState">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="SpinnerRotate"
Storyboard.TargetProperty="Angle"
From="0" To="360" Duration="0:0:01.3"
RepeatBehavior="Forever" />
</Storyboard>
</VisualState>
<VisualState x:Name="Stop"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Canvas>
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>