Quantcast
Viewing all articles
Browse latest Browse all 14

WPF simle animation...need help

Try this code, though its not elegant, it works:

 <Grid>
        <Canvas Height="104" HorizontalAlignment="Left" Margin="74,24,0,0" Name="Canvas1" VerticalAlignment="Top" Width="164" />
        <Line x:Name="linia0" Opacity="0"
                    X1="150" Y1="150"
                    X2="350" Y2="290"
                    Stroke="Black"
                    StrokeThickness="3" Margin="-9,-12,0,0" />
        <Line x:Name="linia1" Opacity="0"
    X1="142" Y1="138"
    X2="300" Y2="50"
    Stroke="Black"
    StrokeThickness="3" />
        <Line x:Name="linia2" Opacity="0"
    X1="299" Y1="51"
    X2="340" Y2="278"
    Stroke="Black"
    StrokeThickness="3" />
        <Line x:Name="linia3" Opacity="0"
    X1="142" Y1="138"
    X2="320" Y2="164"
    Stroke="Red"
    StrokeThickness="4" />
        <Line x:Name="linia4" Opacity="0"
    X1="300" Y1="50"
    X2="240" Y2="207"
    Stroke="Red"
    StrokeThickness="4" />
        <Line x:Name="linia5" Opacity="0"
    X1="340" Y1="278"
    X2="220" Y2="93"
    Stroke="Red"
    StrokeThickness="4" />
        <StackPanel x:Name="rootElement">
            <StackPanel.Resources>
                  <Storyboard x:Key="mystoryboard">
                    <DoubleAnimation
                        Storyboard.TargetName="linia0"
                        Storyboard.TargetProperty="Opacity"
                        From="0.0" To="1.0" Duration="0:0:5"
                        AutoReverse="False"  />
      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(MediaElement.LoadedBehavior)" Storyboard.TargetName="mediaElement">
    <DiscreteObjectKeyFrame KeyTime="0:0:5" Value="{x:Static MediaState.Play}"/>
   </ObjectAnimationUsingKeyFrames>
                    <DoubleAnimation
                        Storyboard.TargetName="linia1"
                        Storyboard.TargetProperty="Opacity"
                        From="0.0" To="1.0" Duration="0:0:10"/>
      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(MediaElement.LoadedBehavior)" Storyboard.TargetName="mediaElement1">
    <DiscreteObjectKeyFrame KeyTime="0:0:10" Value="{x:Static MediaState.Play}"/>
   </ObjectAnimationUsingKeyFrames>
                          <DoubleAnimation
                        Storyboard.TargetName="linia2"
                        Storyboard.TargetProperty="Opacity"
                        From="0.0" To="1.0" Duration="0:0:15"/>
      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(MediaElement.LoadedBehavior)" Storyboard.TargetName="mediaElement2">
    <DiscreteObjectKeyFrame KeyTime="0:0:15" Value="{x:Static MediaState.Play}"/>
   </ObjectAnimationUsingKeyFrames>
                          <DoubleAnimation
                        Storyboard.TargetName="linia3"
                        Storyboard.TargetProperty="Opacity"
                        From="0.0" To="1.0" Duration="0:0:20"/>
      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(MediaElement.LoadedBehavior)" Storyboard.TargetName="mediaElement3">
    <DiscreteObjectKeyFrame KeyTime="0:0:20" Value="{x:Static MediaState.Play}"/>
   </ObjectAnimationUsingKeyFrames>
                          <DoubleAnimation
                        Storyboard.TargetName="linia4"
                        Storyboard.TargetProperty="Opacity"
                        From="0.0" To="1.0" Duration="0:0:25"/>
      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(MediaElement.LoadedBehavior)" Storyboard.TargetName="mediaElement4">
    <DiscreteObjectKeyFrame KeyTime="0:0:20" Value="{x:Static MediaState.Play}"/>
   </ObjectAnimationUsingKeyFrames>
                          <DoubleAnimation
                        Storyboard.TargetName="linia5"
                        Storyboard.TargetProperty="Opacity"
                        From="0.0" To="1.0" Duration="0:0:30"/>
      <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(MediaElement.LoadedBehavior)" Storyboard.TargetName="mediaElement5">
    <DiscreteObjectKeyFrame KeyTime="0:0:30" Value="{x:Static MediaState.Play}"/>
   </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </StackPanel.Resources>

            <Button Content="Click" Height="42" Name="button12" Width="53" Click="button12_Click" />
            <TextBox TextWrapping="Wrap" Text="TextBox"/>
        </StackPanel>
        <MediaElement x:Name="mediaElement" HorizontalAlignment="Left" Height="100" VerticalAlignment="Bottom" Width="100" Margin="44,0,0,97" Visibility="Hidden" Source="file1.mp3" LoadedBehavior="Manual"/>
  <MediaElement x:Name="mediaElement1" HorizontalAlignment="Left" Height="100" VerticalAlignment="Bottom" Width="100" Margin="44,0,0,97" Visibility="Hidden" Source="file2.mp3" LoadedBehavior="Manual"/>
  <MediaElement x:Name="mediaElement2" HorizontalAlignment="Left" Height="100" VerticalAlignment="Bottom" Width="100" Margin="44,0,0,97" Visibility="Hidden" Source="file3.mp3" LoadedBehavior="Manual"/>
  <MediaElement x:Name="mediaElement3" HorizontalAlignment="Left" Height="100" VerticalAlignment="Bottom" Width="100" Margin="44,0,0,97" Visibility="Hidden" Source="file4.mp3" LoadedBehavior="Manual"/>
  <MediaElement x:Name="mediaElement4" HorizontalAlignment="Left" Height="100" VerticalAlignment="Bottom" Width="100" Margin="44,0,0,97" Visibility="Hidden" Source="file5.mp3" LoadedBehavior="Manual"/>

  <MediaElement x:Name="mediaElement5" HorizontalAlignment="Left" Height="100" VerticalAlignment="Bottom" Width="100" Margin="44,0,0,97" Visibility="Hidden" Source="file6.mp3" LoadedBehavior="Manual"/>

    </Grid>

replace the file1.mp3, file2.mp3 etc... with your sound files.

Hope this helps.


Parvez Ansari WPF + Silverlight 4.0 Themes www.nukeation.com Blog : www.wpfblogger.com

Viewing all articles
Browse latest Browse all 14

Trending Articles