Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF - staggering storyboard executions

WPF - staggering storyboard executions

Scheduled Pinned Locked Moved WPF
csharphelpdatabasewpftesting
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gritter
    wrote on last edited by
    #1

    I am developing my first WPF app. It has some animations are essentially the same, but with different targets. I want to stagger their execution so they look random. I developed a storyboard for each target and gave each sb a unique name. To insert the delay, I am calling the storyboards from the code-behind. For testing I am using a button for my trigger. Eventually, form_load will trigger the animations. Also for testing purpose, I am only trying to run two storyboards, begin the 2nd one 8 seconds after the first. My problem is that my storyboards both execution at the same time. After clicking the button, there's an 8 second delay and then they both run. I've tried separating the storyboards in two separate sub's. I've tried dimensioning individual storyboard variables. So far nothing seems to make a difference. I am sure this should be possible. In fact I imagine it's fairly common. Any help will be appreciated. See code below...

    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Windows
    Imports System.Threading
    Imports System.Windows.Media
    Imports System.Windows.Media.Animation
    Imports System.Windows.Navigation

    Class Window1

    Private Sub cmdStart\_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    
        'Call RunStoryBoard("GrowDrop1")
        Call RunStoryBoard1()
    
        'Thread.Sleep(800)
        Call Delay(8000)
    
        'Call RunStoryBoard("GrowDrop2")
        Call RunStoryBoard2()
    
    End Sub
    
    Private Sub RunStoryBoard(ByVal sbName As String)
        Dim myStoryBoard As Storyboard = DirectCast(FindResource(sbName), Storyboard)
    
        myStoryBoard.Begin(Me)
    
    End Sub
    
    Private Sub RunStoryBoard1()
        Dim myStoryBoard1 As Storyboard = DirectCast(FindResource("GrowDrop1"), Storyboard)
    
        myStoryBoard1.Begin(Me)
    
    End Sub
    
    Private Sub RunStoryBoard2()
        Dim myStoryBoard2 As Storyboard = DirectCast(FindResource("GrowDrop2"), Storyboard)
    
        myStoryBoard2.Begin(Me)
    
    End Sub
    
    Public Sub Delay(ByVal Milliseconds As UShort)
        Dim DelayTime As TimeSpan
        Dim NewTime As DateTime = DateTime.Now.AddSeconds(Milliseconds / 1000)
        Do
            DelayTime = NewTime.Subtract(DateTime.Now)
    
        Loop While DelayTime.Seconds > 0
    End Sub
    

    End Class

    G 1 Reply Last reply
    0
    • G gritter

      I am developing my first WPF app. It has some animations are essentially the same, but with different targets. I want to stagger their execution so they look random. I developed a storyboard for each target and gave each sb a unique name. To insert the delay, I am calling the storyboards from the code-behind. For testing I am using a button for my trigger. Eventually, form_load will trigger the animations. Also for testing purpose, I am only trying to run two storyboards, begin the 2nd one 8 seconds after the first. My problem is that my storyboards both execution at the same time. After clicking the button, there's an 8 second delay and then they both run. I've tried separating the storyboards in two separate sub's. I've tried dimensioning individual storyboard variables. So far nothing seems to make a difference. I am sure this should be possible. In fact I imagine it's fairly common. Any help will be appreciated. See code below...

      Imports System
      Imports System.IO
      Imports System.Net
      Imports System.Windows
      Imports System.Threading
      Imports System.Windows.Media
      Imports System.Windows.Media.Animation
      Imports System.Windows.Navigation

      Class Window1

      Private Sub cmdStart\_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
      
          'Call RunStoryBoard("GrowDrop1")
          Call RunStoryBoard1()
      
          'Thread.Sleep(800)
          Call Delay(8000)
      
          'Call RunStoryBoard("GrowDrop2")
          Call RunStoryBoard2()
      
      End Sub
      
      Private Sub RunStoryBoard(ByVal sbName As String)
          Dim myStoryBoard As Storyboard = DirectCast(FindResource(sbName), Storyboard)
      
          myStoryBoard.Begin(Me)
      
      End Sub
      
      Private Sub RunStoryBoard1()
          Dim myStoryBoard1 As Storyboard = DirectCast(FindResource("GrowDrop1"), Storyboard)
      
          myStoryBoard1.Begin(Me)
      
      End Sub
      
      Private Sub RunStoryBoard2()
          Dim myStoryBoard2 As Storyboard = DirectCast(FindResource("GrowDrop2"), Storyboard)
      
          myStoryBoard2.Begin(Me)
      
      End Sub
      
      Public Sub Delay(ByVal Milliseconds As UShort)
          Dim DelayTime As TimeSpan
          Dim NewTime As DateTime = DateTime.Now.AddSeconds(Milliseconds / 1000)
          Do
              DelayTime = NewTime.Subtract(DateTime.Now)
      
          Loop While DelayTime.Seconds > 0
      End Sub
      

      End Class

      G Offline
      G Offline
      gritter
      wrote on last edited by
      #2

      I think I solved my own problem. Rather than trying to run multiple storyboards, each containing animations for a single target, I tired putting all of the animations for all of the targets into a single storyboard and arrange them on the timeline so they appear to fire in a random order. That seems to be working fairly well. My only issue now is how to set it up so it runs continuously. What complicates this is that each target has 3 animations associated with it. Each target is a droplet. The first 2 animations are an X and a Y scale transformations, to make the droplet grow. The third is a translate transformation as the droplet falls down the screen. I use this set of 3 animations for each of the droplets. I am not sure yet how to set this up so the animations for a target are repeated automatically in the proper sequence. If anyone has an ideas on this, again I would appreciate the help.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups