5/8
Animatsiyani boshlash uchun elementning usuli deyiladi BeginAnimation(). Bu
usul animatsiya
qilinadigan bog'liqlik xususiyati va animatsiya ob'ektining o'ziga o'tadi.
Bunday holda, tugmaning kengligi joriy qiymatdan 150 pikselgacha o'zgaradi. Va bu o'zgarish 3
soniya davom etadi.
Agar animatsiya
takrorlanishini istasak, RepeatBehavior xususiyatidan foydalanishimiz mumkin:
Bunday holda, animatsiya ikki marta takrorlanadi. Biz takrorlash
vaqtini ham belgilashimiz
mumkin:
Bu erda takrorlash vaqti 7 soniya. Animatsiya 3
soniya davom etadi, ya'ni 7/3 takrorlash bo'ladi:
ikkita to'liq takrorlash va ikkinchi holatda kenglik faqat kerakli kenglikning
uchdan bir qismiga
oshadi.
Xususiyatning teskari yo'nalishda silliq o'zgarishini o'rnatish uchun
AutoReverse xususiyatini
qo'llang:
Tugallangan tadbir
Animatsiya
tugagach,
tugallangan hodisa yaratiladi, biz uni boshqarishimiz mumkin:
1
2
3
4
5
6
DoubleAnimation buttonAnimation =
new
DoubleAnimation();
buttonAnimation.From = helloButton.ActualWidth;
buttonAnimation.To = 150;
buttonAnimation.Duration = TimeSpan.FromSeconds(3);
buttonAnimation.RepeatBehavior =
new
RepeatBehavior(2);
helloButton.BeginAnimation(Button.WidthProperty, buttonAnimation);
1
2
buttonAnimation.Duration = TimeSpan.FromSeconds(3);
buttonAnimation.RepeatBehavior =
new
RepeatBehavior(TimeSpan.FromSeconds(7));
1
2
buttonAnimation.AutoReverse =
true
;
buttonAnimation.RepeatBehavior =
new
RepeatBehavior(5);
1
2
3
4
5
6
7
8
9
10
o'n bir
12
13
14
public
MainWindow()
{
InitializeComponent();
DoubleAnimation buttonAnimation =
new
DoubleAnimation();
buttonAnimation.From = helloButton.ActualWidth;
buttonAnimation.To = 150;
buttonAnimation.Duration = TimeSpan.FromSeconds(5);
buttonAnimation.Completed += ButtonAnimation_Completed;
helloButton.BeginAnimation(Button.WidthProperty, buttonAnimation);
}
private
void
ButtonAnimation_Completed(
object
sender, EventArgs e)
{