如何使 WPF TextBlock 在其值更新时旋转?

发布于 2024-10-20 12:06:41 字数 1010 浏览 1 评论 0原文

每当绑定更新时,我都会尝试将 TextBlock 旋转 360 度。

从我读过的所有内容来看,以下内容应该有效,但没有任何效果。我做错了什么?

<TextBlock VerticalAlignment="Center" Text="{Binding Total, NotifyOnTargetUpdated=True}">

    <TextBlock.RenderTransform>
        <RotateTransform x:Name="TotalSpinTransform" Angle="0"/>
    </TextBlock.RenderTransform>

    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <EventTrigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)" 
                            From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.EnterActions>
        </EventTrigger>
    </TextBlock.Triggers>

</TextBlock>       

I'm trying to spin a TextBlock 360 degrees whenever it's binding updates.

From everything I've read the following should work, however it doesn't have any effect. What am I doing wrong?

<TextBlock VerticalAlignment="Center" Text="{Binding Total, NotifyOnTargetUpdated=True}">

    <TextBlock.RenderTransform>
        <RotateTransform x:Name="TotalSpinTransform" Angle="0"/>
    </TextBlock.RenderTransform>

    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <EventTrigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)" 
                            From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.EnterActions>
        </EventTrigger>
    </TextBlock.Triggers>

</TextBlock>       

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦在深巷 2024-10-27 12:06:41

EnterActionsExitActions 均不适用于 EventTrigger。不幸的是,这些属性是在 TriggerBase 上定义的,因此它们出现在 EventTrigger 上。试试这个:

    <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)" 
                        From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/>
                </Storyboard>
            </BeginStoryboard>
    </EventTrigger>

Neither EnterActions nor ExitActions are applicable to EventTrigger. Unfortunately, these properties are defined on TriggerBase so they are present on an EventTrigger. Try this:

    <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)" 
                        From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/>
                </Storyboard>
            </BeginStoryboard>
    </EventTrigger>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文