在 Universal Windows 中通过故事板设置 TextBlock 前景不起作用

Set TextBlock Foreground via Storyboard in Universal Windows doesn't work

我尝试使用 Storyboard 为 TextBlock 前景色设置动画。它在 WPF 中完美运行,但在 Universal Windows.

中似乎不起作用

这是我的代码:

<Page
    x:Class="TestApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TestApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <TextBlock x:Name="tbHello" Text="Hello World" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBlock.Foreground>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"
                ColorInterpolationMode="ScRgbLinearInterpolation">
                    <GradientStop Color="#ff666666" Offset="-0.2" />
                    <GradientStop Color="#ffffffff" Offset="-0.1" />
                    <GradientStop Color="#ff666666" Offset="0" />
                </LinearGradientBrush>
            </TextBlock.Foreground>
            <TextBlock.Triggers>
                <EventTrigger>
                    <BeginStoryboard>
                        <Storyboard RepeatBehavior="Forever">
                            <DoubleAnimation Storyboard.TargetName="tbHello"
                                             Storyboard.TargetProperty="(TextElement.Foreground).(LinearGradientBrush.GradientStops)[0].(GradientStop.Offset)"
                                             From="-0.2" To="1.5" Duration="0:0:1.5" />
                            <DoubleAnimation Storyboard.TargetName="tbHello"
                                             Storyboard.TargetProperty="(TextElement.Foreground).(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"
                                             From="-0.1" To="1.6" Duration="0:0:1.5" />
                            <DoubleAnimation Storyboard.TargetName="tbHello"
                                             Storyboard.TargetProperty="(TextElement.Foreground).(LinearGradientBrush.GradientStops)[2].(GradientStop.Offset)"
                                             From="0" To="1.7" Duration="0:0:1.5" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </TextBlock.Triggers>
        </TextBlock>

    </Grid>
</Page>

知道为什么它不能在通用 Windows 平台上运行吗?

谢谢

您定义的动画被视为 depended animation, so as I've tried it will work if you set EnableDependentAnimation="True",但正如 MSDN 所说 - 请谨慎使用。

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock x:Name="tbHello" Text="Hello World" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center">
        <TextBlock.Foreground>
            <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"
        ColorInterpolationMode="ScRgbLinearInterpolation">
                <GradientStop Color="#ff666666" Offset="-0.2" />
                <GradientStop Color="#ffffffff" Offset="-0.1" />
                <GradientStop Color="#ff666666" Offset="0" />
            </LinearGradientBrush>
        </TextBlock.Foreground>
        <TextBlock.Triggers>
            <EventTrigger>
                <BeginStoryboard>
                    <Storyboard RepeatBehavior="Forever">
                        <DoubleAnimation Storyboard.TargetName="tbHello" EnableDependentAnimation="True"
                                     Storyboard.TargetProperty="(TextElement.Foreground).(LinearGradientBrush.GradientStops)[0].(GradientStop.Offset)"
                                     From="-0.2" To="1.5" Duration="0:0:1.5" />
                        <DoubleAnimation Storyboard.TargetName="tbHello" EnableDependentAnimation="True"
                                     Storyboard.TargetProperty="(TextElement.Foreground).(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"
                                     From="-0.1" To="1.6" Duration="0:0:1.5" />
                        <DoubleAnimation Storyboard.TargetName="tbHello" EnableDependentAnimation="True"
                                     Storyboard.TargetProperty="(TextElement.Foreground).(LinearGradientBrush.GradientStops)[2].(GradientStop.Offset)"
                                     From="0" To="1.7" Duration="0:0:1.5" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </TextBlock.Triggers>
    </TextBlock>
</Grid>