VisualStateManager.GoToState(FrameworkElement, String, Boolean) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コントロールを 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
返品
true コントロールが正常に新しい状態に遷移した場合。それ以外の場合は false。
例外
例
次の例では、 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
注釈
ControlTemplateでVisualStateManagerを使用するコントロールの状態を変更する場合は、GoToState メソッドを呼び出します。 GoToElementState メソッドを呼び出して、ControlTemplateの外部にある要素の状態を変更します (たとえば、UserControlまたは単一の要素でVisualStateManagerを使用する場合)。