我有一个TextBlock,我希望在某些情况下为前景设置LinearGradient动画。在其他情况下,颜色需要是简单的纯色。我已经能够使Gradient Animation工作,但只有在没有设置前景色的情况下才能使用。
XAML
<LinearGradientBrush x:Key="AlarmTextBrush" MappingMode="Absolute" SpreadMethod="Pad">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="Black" Offset=".5" />
</LinearGradientBrush>
<TextBlock FontWeight="{Binding Path=Value, Converter={StaticResource BoldConverter}, IsAsync=True}" Text="{Binding Path=DisplayName, IsAsync=True}" Foreground="{Binding Path=Value, Converter={StaticResource TextColorConverter}, ConverterParameter=Label, IsAsync=True}">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Value="true">
<DataTrigger.Binding>
<MultiBinding>
<MultiBinding.Converter>
<conv:IsBlinkingStatusConverter />
</MultiBinding.Converter>
<Binding Path="Value" IsAsync="True" />
<Binding Path="IsAcknowledged" IsAsync="True" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="{StaticResource AlarmTextBrush}" />
<DataTrigger.EnterActions>
<BeginStoryboard Name="RollingGradientText">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetProperty="(TextBlock.Foreground).(GradientBrush.GradientStops)[1].(GradientStop.Offset)" From=".2" To="1.5" By=".1" Duration="0:0:3"/>
<DoubleAnimation Storyboard.TargetProperty="(TextBlock.Foreground).(GradientBrush.GradientStops)[2].(GradientStop.Offset)" From="1" To="1.5" By=".1" Duration="0:0:3"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="RollingGradientText" />
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
如果从TextBlock中删除前景属性,则此方法有效。如果我离开绑定甚至只是将其设置为白色,它将会出错。我需要能够将前景设置为不同,并且仍然可以使用动画。它几乎就像动画在完成解析GradientBrush而不是SolidColorBrush之前尝试触发一样。