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

时间:2015-12-12 05:53:39

标签: c# xaml winrt-xaml win-universal-app

我尝试使用Storyboard为TextBlock前景色设置动画。它在WPF中完美运行,但它似乎不适用于通用Windows。

这是我的代码:

store.dispatch(fetchLocations());
ReactDOM.render(<App store={store} />, mountpoint);

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

由于

1 个答案:

答案 0 :(得分:1)

您定义的动画被视为depended animation,因此,如果您设置EnableDependentAnimation="True",我会尝试它,但正如MSDN所说 - 请谨慎使用它。 / p>

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