VisualStateManager.GoToState(FrameworkElement, String, Boolean) Metoda

Definice

Přemísí ovládací prvek mezi dvěma stavy. Pomocí této metody lze převést stavy u ovládacího prvku, který má 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

Parametry

control
FrameworkElement

Ovládací prvek pro přechod mezi stavy.

stateName
String

Stav, na který se má přejít.

useTransitions
Boolean

true použít VisualTransition objekt pro přechod mezi stavy; jinak , false.

Návraty

truepokud řízení úspěšně přešlo do nového stavu; v opačném případě . false

Výjimky

control je null.

nebo

stateName je null.

Příklady

Následující příklad ukazuje ovládací prvek, který používá metodu GoToState k přechodu mezi stavy. Celý příklad najdete v tématu Vytvoření ovládacího prvku, který má přizpůsobitelný vzhled.

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

Poznámky

GoToState Volání metody pokud měníte stavy v ovládacím prvku, který používá VisualStateManager v jeho ControlTemplate. GoToElementState Volání metody pro změnu stavů u elementu mimo prvek ControlTemplate (například pokud používáte VisualStateManager v UserControl jednom prvku nebo v jednom prvku).

Platí pro