Monday, 30 May 2011

Simple XAML fade

Getting a control in WPF or Silverlight to fade in on a specific event is a doddle.

Here’s an example of a menu control I created that fades in when the StackPanel has loaded. 

The StackPanel contains multiple menu item controls, each of which comprises of an image and some text.

The key points here are:

  • EventTrigger RoutedEvent which tells the animation to start on the StackPanel.Loaded event
  • Use a double animation, double being the opacity value data type
<StackPanel x:Name="MenuContainer" Orientation="Horizontal" HorizontalAlignment="Center">

<EventTrigger RoutedEvent="StackPanel.Loaded">
<DoubleAnimation Storyboard.TargetName="MenuContainer"
Duration="0:0:3" />


Full source:

1 comment:

  1. It would be great if you can show the source code.