EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

VisualStateManager.GoToState Method

July 28, 2014

Transitions the control between two states.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

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 null.

ArgumentNullException

stateName is null.

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.


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);
    }

}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Afficher:
© 2014 Microsoft