VisualStateManager.GoToState(FrameworkElement, String, Boolean) Metoda

Definicja

Przenosi kontrolkę między dwoma stanami. Użyj tej metody, aby przenieść stany kontroli, która ma element 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

Kontrolka przejścia między stanami.

stateName
String

Stan do przejścia do.

useTransitions
Boolean

true aby użyć VisualTransition obiektu do przejścia między stanami; w przeciwnym razie false.

Zwraca

true jeśli kontrolka została pomyślnie przeniesiona do nowego stanu; w przeciwnym razie , false.

Wyjątki

control to null.

-lub-

stateName to null.

Przykłady

W poniższym przykładzie pokazano kontrolkę, która używa GoToState metody do przejścia między stanami. W całym przykładzie zobacz Tworzenie kontrolki, która ma dostosowywalny wygląd.

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

Uwagi

Wywołaj metodę, GoToState jeśli zmieniasz stany w kontrolce, która używa elementu VisualStateManager w pliku ControlTemplate. Wywołaj metodę GoToElementState , aby zmienić stany elementu spoza ControlTemplate elementu (na przykład jeśli używasz elementu VisualStateManager w elemecie UserControl lub w jednym elemecie).

Dotyczy