标签上的字符串动画

发布于 2024-11-08 18:22:06 字数 3977 浏览 3 评论 0原文

我有一个指示操作模式的控件。根据当前模式(自动、手动或无),它会向左或向右旋转几度,并更改标签的内容。旋转已经很好了。但无论当前状态如何,标签的内容都不会显示。控制模板是否有任何错误(我通过删除第三个状态稍微简化了模板)?或者还有什么事情不应该这样吗?

提前致谢!

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如若梦似彩虹 2024-11-15 18:22:06

动画按预期工作。 Blend 没有显示它。无论如何,原因仍然未知。

The animation works as expected. It's Blend that doesn't show it. Anyway, the reason is still unknown.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文