标签上的StringAnimation

时间:2011-05-19 12:31:42

标签: wpf templates animation wpf-controls controltemplate

我有一个指示操作模式的控件。根据当前模式(自动,手动或无),它向左或向右旋转几度,并且还会更改标签的内容。旋转工作正常。但无论目前的状态如何,标签的内容都不会显示出来。控制模板中是否有任何错误(我通过删除第三个状态简化了模板)?或者还有什么不应该的方式吗?

提前致谢!

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

1 个答案:

答案 0 :(得分:0)

动画按预期工作。这是Blend,没有显示它。无论如何,原因还不得而知。