Szerkesztés

Megosztás a következőn keresztül:


VisualStateManager.GoToState(FrameworkElement, String, Boolean) Method

Definition

Transitions the control between two states. Use this method to transition states on control that has a ControlTemplate.

public:
 static bool GoToState(System::Windows::FrameworkElement ^ control, System::String ^ stateName, bool useTransitions);
public static bool GoToState (System.Windows.FrameworkElement control, string stateName, bool useTransitions);
static member GoToState : System.Windows.FrameworkElement * string * bool -> bool
Public Shared Function GoToState (control As FrameworkElement, stateName As String, useTransitions As Boolean) As Boolean

Parameters

control
FrameworkElement

The control to transition between states.

stateName
String

The state to transition to.

useTransitions
Boolean

true to use a VisualTransition object to transition between states; otherwise, false.

Returns

true if the control successfully transitioned to the new state; otherwise, false.

Exceptions

control is null.

-or-

stateName is null.

Examples

The following example demonstrates a control that uses the GoToState method to transition between states. For the entire example, see Creating a Control That Has a Customizable Appearance.

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

Remarks

Call the GoToState method if you are changing states in a control that uses the VisualStateManager in its ControlTemplate. Call the GoToElementState method to change states on an element outside of a ControlTemplate (for example, if you use a VisualStateManager in a UserControl or in a single element).

Applies to