WPF 动画效果
1. (Visibility)闪烁三下,停下两秒,循环:
XAML:
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition Width="Auto"></ColumnDefinition> </Grid.ColumnDefinitions> <Label Name="WarningShineLabel" Content="充电" Background="DarkRed"></Label> </Grid>
CS
private void SetVisibilityShine() { ObjectAnimationUsingKeyFrames okf = new ObjectAnimationUsingKeyFrames(); okf.Duration = new TimeSpan(0, 0, 0, 0, 4500); okf.RepeatBehavior = RepeatBehavior.Forever; okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 0))); okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 0, 0, 500))); okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 0, 0, 1000))); okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 0, 0, 1500))); okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 0, 0, 2000))); okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 0, 0, 2500))); okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 0, 0, 4500))); WarningShineLabel.BeginAnimation(Label.VisibilityProperty, okf); }
2. 平移:
XAML
<Label Name="AirOutAnimation"> <Label.Content> <Image Source="../Icons/flow.png"></Image> <!--一张图片--> </Label.Content> </Label>
CS
ThicknessAnimation ta = new ThicknessAnimation(); ta.From = new Thickness(60, 0, 0, 0); ta.To = new Thickness(0, 0, 0, 0); ta.Duration = TimeSpan.FromSeconds(1.5); ta.RepeatBehavior = RepeatBehavior.Forever; AirOutAnimation.BeginAnimation(Label.MarginProperty, ta);