domingo, 28 de enero de 2007

Programmatic Fade In & Out sample

Animating the Opacity property is possible to achieve the fade in&out effect.

The source & bits can be downloaded from here.

The following is the C# code used,

#region Fade in
// Create a storyboard to contain the animations.
Storyboard storyboard = new Storyboard();
TimeSpan duration = new TimeSpan(0, 0, 1);

// Create a DoubleAnimation to fade the not selected option control
DoubleAnimation animation = new DoubleAnimation();

animation.From = 0.0;
animation.To = 1.0;
animation.Duration = new Duration(duration);
// Configure the animation to target de property Opacity
Storyboard.SetTargetName(animation, Img1.Name);
Storyboard.SetTargetProperty(animation, new PropertyPath(Control.OpacityProperty));
// Add the animation to the storyboard
storyboard.Children.Add(animation);

// Begin the storyboard
storyboard.Begin(this);

#endregion


The image used comes from here. The executed sample looks like this:


WPF Fade sample

4 comentarios:

si dijo...

Thank you very much!

Unknown dijo...

Thanks for sharing. Here's the VB version:
' Create a storyboard to contain the animations.
Dim storyboard As New Storyboard()
Dim duration As New TimeSpan(0, 0, 1)

' Create a DoubleAnimation to fade the not selected option control
Dim animation As New DoubleAnimation()

animation.From = 0.0
animation.To = 1.0
animation.Duration = New Duration(duration)

' Configure the animation to target de property Opacity
storyboard.SetTargetName(animation, Img1.Name)
storyboard.SetTargetProperty(animation, New PropertyPath(Control.OpacityProperty))
' Add the animation to the storyboard
storyboard.Children.Add(animation)

' Begin the storyboard
storyboard.Begin(Me)

Unknown dijo...

And if you want the image to fade in and out repeatedly, just add:

storyboard.RepeatBehavior = RepeatBehavior.Forever()

' and
animation.AutoReverse = True

Video Teraveloka dijo...

Pembahasan kali ini teruntuk kamu yang sedang kesulitan login akun sbobet karena muncul keterangan "Sbobet Password Policy". Jangan panik karena kamu hanya diperintahkan untuk Ganti Password Sbobet Online milik (Baca Selengkapnya Disini...)