标签上的字符串动画
我有一个指示操作模式的控件。根据当前模式(自动、手动或无),它会向左或向右旋转几度,并更改标签的内容。旋转已经很好了。但无论当前状态如何,标签的内容都不会显示。控制模板是否有任何错误(我通过删除第三个状态稍微简化了模板)?或者还有什么事情不应该这样吗?
提前致谢!
<ControlTemplate TargetType="{x:Type local:OperationModeIndicator}">
<Grid x:Name="rootGrid" RenderTransformOrigin="0.5,0.525">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="OperationModeStates">
<VisualState x:Name="None">
<Storyboard>
<StringAnimationUsingKeyFrames Storyboard.TargetName="contentLabel" Storyboard.TargetProperty="Content" >
<DiscreteStringKeyFrame Value="" />
</StringAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="rootGrid" >
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="contentLabel">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Automatic">
<Storyboard>
<StringAnimationUsingKeyFrames Storyboard.TargetName="contentLabel" Storyboard.TargetProperty="Content" >
<DiscreteStringKeyFrame Value="A" />
</StringAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="rootGrid">
<EasingDoubleKeyFrame KeyTime="0" Value="-30"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="contentLabel">
<EasingDoubleKeyFrame KeyTime="0" Value="30"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RenderTransform>
<TransformGroup>
<RotateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Label x:Name="contentLabel" Foreground="#FFDA1D1D" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="48" RenderTransformOrigin="0.5,0.525" >
<Label.RenderTransform>
<TransformGroup>
<RotateTransform/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Path Stroke="Gray" StrokeThickness="5">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="35 10" >
<ArcSegment Point="65 10" Size="45 45" RotationAngle="0" IsLargeArc="True" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Line X1="2.5" X2="2.5" Y1="0" Y2="20" StrokeThickness="5" Stroke="Gray" HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
I have a control that indicates the operation mode. Depending on the current mode (automatic, manual or none) it rotates several degrees to the left or right and also changes a label's content. The rotation works fine already. But the label's content doesn't show up, regardless of the current state. Is there any mistake in the control template (I simplified the template a bit by removing the third state)? Or is there anything else not the way it should be?
Thanks in advance!
<ControlTemplate TargetType="{x:Type local:OperationModeIndicator}">
<Grid x:Name="rootGrid" RenderTransformOrigin="0.5,0.525">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="OperationModeStates">
<VisualState x:Name="None">
<Storyboard>
<StringAnimationUsingKeyFrames Storyboard.TargetName="contentLabel" Storyboard.TargetProperty="Content" >
<DiscreteStringKeyFrame Value="" />
</StringAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="rootGrid" >
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="contentLabel">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Automatic">
<Storyboard>
<StringAnimationUsingKeyFrames Storyboard.TargetName="contentLabel" Storyboard.TargetProperty="Content" >
<DiscreteStringKeyFrame Value="A" />
</StringAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="rootGrid">
<EasingDoubleKeyFrame KeyTime="0" Value="-30"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="contentLabel">
<EasingDoubleKeyFrame KeyTime="0" Value="30"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RenderTransform>
<TransformGroup>
<RotateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Label x:Name="contentLabel" Foreground="#FFDA1D1D" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="48" RenderTransformOrigin="0.5,0.525" >
<Label.RenderTransform>
<TransformGroup>
<RotateTransform/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Path Stroke="Gray" StrokeThickness="5">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="35 10" >
<ArcSegment Point="65 10" Size="45 45" RotationAngle="0" IsLargeArc="True" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Line X1="2.5" X2="2.5" Y1="0" Y2="20" StrokeThickness="5" Stroke="Gray" HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
动画按预期工作。 Blend 没有显示它。无论如何,原因仍然未知。
The animation works as expected. It's Blend that doesn't show it. Anyway, the reason is still unknown.