Hi there,
you can do all you need with XAML only - there's no need for code. For instance:
<Windowx:Class="WpfTests.OpacityAnimationWithSound"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow"Height="439"Width="725"><Grid><Grid.RowDefinitions><RowDefinitionHeight="*"/><RowDefinitionHeight="Auto"/></Grid.RowDefinitions><!-- Initially, the Canvas is transparent --><Canvasx:Name="canvas"Opacity="0"><Linex:Name="linia0"X1="150"Y1="150"X2="350"Y2="290"Stroke="Black"StrokeThickness="3"Margin="-9,-12,0,0"/><Linex:Name="linia1"X1="142"Y1="138"X2="300"Y2="50"Stroke="Black"StrokeThickness="3"/><Linex:Name="linia2"X1="299"Y1="51"X2="340"Y2="278"Stroke="Black"StrokeThickness="3"/><Linex:Name="linia3"X1="142"Y1="138"X2="320"Y2="164"Stroke="Red"StrokeThickness="4"/><Linex:Name="linia4"X1="300"Y1="50"X2="240"Y2="207"Stroke="Red"StrokeThickness="4"/><Linex:Name="linia5"X1="340"Y1="278"X2="220"Y2="93"Stroke="Red"StrokeThickness="4"/></Canvas><Buttonx:Name="cmdStartAnimation"Grid.Row="1"Margin="5"Padding="3"Content="Start Animation"><Button.Triggers><EventTriggerRoutedEvent="Button.Click"><EventTrigger.Actions><!-- Fade in the Canvas control --><BeginStoryboard><Storyboard><DoubleAnimationStoryboard.TargetName="canvas"Storyboard.TargetProperty="Opacity"From="0.0"To="1.0"Duration="0:0:3"AutoReverse="False"/></Storyboard></BeginStoryboard><!-- Play sound --><SoundPlayerActionSource="/Resources/MediaPlayer/bangbang.wav"/></EventTrigger.Actions></EventTrigger></Button.Triggers></Button></Grid></Window>
The SoundPlayerAction makes it easy to add sound. For the sample above, I copied a wav-file into a folder of my solution (Resources\MediaPlayer\...) with itsBuild Action set to Resource and its Copy to Output Directoryset to Do not copy . Other than that, I wouldnt' animate single lines if what you want to do is to fade everything in. So I to a) changed the lines so that they're actuallyin the canvas. As a result, I can simply fade in the Canvas control rather than the lines themselves.
Cheers,
Olaf
http://blogs.intuidev.com