VisualStateManager.GoToState(FrameworkElement, String, Boolean) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기