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(, , , , );
okf.RepeatBehavior = RepeatBehavior.Forever;
okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(, , )));
okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(, , , , )));
okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(, , , , )));
okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(, , , , )));
okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(, , , , )));
okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(, , , , )));
okf.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(, , , , ))); 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(, , , );
ta.To = new Thickness(, , , );
ta.Duration = TimeSpan.FromSeconds(1.5);
ta.RepeatBehavior = RepeatBehavior.Forever;
AirOutAnimation.BeginAnimation(Label.MarginProperty, ta);