Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 3
 GoToState Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
VisualStateManager..::.GoToState Method

Transitions the control between two states.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Shared Function GoToState ( _
    control As Control, _
    stateName As String, _
    useTransitions As Boolean _
) As Boolean
Visual Basic (Usage)
Dim control As Control
Dim stateName As String
Dim useTransitions As Boolean
Dim returnValue As Boolean

returnValue = VisualStateManager.GoToState(control, _
    stateName, useTransitions)
C#
public static bool GoToState(
    Control control,
    string stateName,
    bool useTransitions
)

Parameters

control
Type: System.Windows.Controls..::.Control
The control to transition between states.
stateName
Type: System..::.String
The state to transition to.
useTransitions
Type: System..::.Boolean
true to use a VisualTransition to transition between states; otherwise, false.

Return Value

Type: System..::.Boolean
true if the control successfully transitioned to the new state; otherwise, false.
ExceptionCondition
ArgumentNullException

control is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentNullException

stateName is nullNothingnullptra null reference (Nothing in Visual Basic).

The GoToStateCore method performs the logic necessary to appropriately start and stop the storyboards that are associated with a transition. When a control calls GoToState to change its state, the VisualStateManager does the following:

  • First, if the VisualState that the control is going to has a Storyboard, the storyboard begins. Then, if the VisualState that the control is coming from has a Storyboard, the storyboard ends.

  • If the control is already in the stateName state, GoToState takes no action returns true.

  • If stateName doesn't exist in the ControlTemplate of control, GoToState takes no action and returns false.

The following example demonstrates a control using the GoToStateCore method to transition between states. For the entire example, see How to: Create a New Control by Creating a ControlTemplate.

Visual Basic
Private Sub UpdateStates(ByVal useTransitions As Boolean)
    If Value >= 0 Then
        VisualStateManager.GoToState(Me, "Positive", useTransitions)
    Else
        VisualStateManager.GoToState(Me, "Negative", useTransitions)
    End If

    If isFocused Then
        VisualStateManager.GoToState(Me, "Focused", useTransitions)
    Else
        VisualStateManager.GoToState(Me, "Unfocused", useTransitions)
    End If

End Sub
C#
private void UpdateStates(bool useTransitions)
{
    if (Value >= 0)
    {
        VisualStateManager.GoToState(this, "Positive", useTransitions);
    }
    else
    {
        VisualStateManager.GoToState(this, "Negative", useTransitions);
    }

    if (isFocused)
    {
        VisualStateManager.GoToState(this, "Focused", useTransitions);
    }
    else
    {
        VisualStateManager.GoToState(this, "Unfocused", useTransitions);
    }

}

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker