WPF为提示信息文本增加闪烁效果
程序通常需要显示某些提醒用户警示的信息,如:收件箱(40)其中数量闪烁就会起到警示效果。可以适用如下Storyboard实现:
<ItemsControl.ItemTemplate> <DataTemplate> <Button Command="{x:Static local:QueryRecordItem.OpenCommand}" FocusVisualStyle="{x:Null}" Focusable="False" ContextMenu="{StaticResource ShellContextMenu}" ToolTip="{Binding ToolTip}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Description}"/> <TextBlock Text="{Binding TipText}" Foreground="Red" Visibility="{Binding Converter={x:Static jsm:Converters.BooleanToVisibility}, Path=HasItem, ConverterParameter=true}"/> <Border Background="Red" CornerRadius="5" Visibility="{Binding Converter={x:Static jsm:Converters.BooleanToVisibility}, Path=HasItem}"> <Border.Triggers> <EventTrigger RoutedEvent="Loaded"> <BeginStoryboard> <Storyboard BeginTime="0:0:0" AutoReverse="True" RepeatBehavior="Forever"> <ColorAnimation From="Red" To="Navy" RepeatBehavior="Forever" Storyboard.TargetProperty="Background.Color"> </ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> </Border.Triggers> <TextBlock Text="{Binding TipText}" Foreground="White"/> </Border> </StackPanel> </Button> </DataTemplate> </ItemsControl.ItemTemplate>