VisualStateManager.GoToState(FrameworkElement, String, Boolean) メソッド

定義

コントロールを 2 つの状態間で切り替えます。 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

パラメーター

control
FrameworkElement

状態を遷移するコントロール。

stateName
String

切り替え先の状態。

useTransitions
Boolean

VisualTransition オブジェクトを使用して状態を遷移させる場合は true。それ以外の場合は false

戻り値

Boolean

コントロールが新しい状態に正常に遷移した場合は true。それ以外の場合は false

例外

controlnullです。

または stateNamenullです。

次の例では、メソッドを使用して状態間を GoToState 遷移するコントロールを示します。 例全体については、「 カスタマイズ可能な外観を持つコントロールの作成」を参照してください。

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

注釈

を使用するGoToStateコントロールの状態を変更する場合は、メソッドをVisualStateManagerControlTemplate呼び出します。 メソッドをGoToElementState呼び出して、外部の要素の状態をControlTemplate変更します (たとえば、a または 1 つの要素でUserControl使用VisualStateManagerする場合)。

適用対象