views:

21

answers:

1

I'm building a Silverlight 4 UserControl in Blend which has three VisualStates.

I would like to have the states change from the first to the second state after a delay of a few seconds, second to third after a few more seconds, third to first after another delay, and continue rotating like that.

Essentially, this is a very primitive "ad rotator", using some static images for a prototype I'm building.

Is it possible to do this using Blend? If so, how? I'm able to use TimerTriggers and ActivateStateAction behaviors to create the first full rotation, but I'm not sure how to reset the timers, or whether another approach will work better.

A: 
  1. Name the control with an x:Name label; I named mine "ControlName"
  2. Declare a TimerTrigger:

    <ei:TimerTrigger MillisecondsPerTick="3000">
        <ei:CallMethodAction MethodName="NextState" TargetObject="{Binding ElementName=ControlName}"/>
    </ei:TimerTrigger>
    
  3. Implement this code with your states in the code behind. Yes. The Code Behind.

    Public Sub NextState()

        Select Case Me.RotateImageStates.CurrentState.Name
            Case "run1"
                VisualStateManager.GoToState(Me, "run2", True)
            Case "run2"
                VisualStateManager.GoToState(Me, "run3", True)
            Case "run3"
                VisualStateManager.GoToState(Me, "run1", True)
            Case Else
                VisualStateManager.GoToState(Me, "run1", True)
        End Select   
    

    End Sub

  4. ...?

  5. Profit!

Name the control with an x:Name="SomeName"

Rob Perkins