GoToStateCore method

VisualStateManager.GoToStateCore method

When overridden in a derived class, transitions a control between states.


protected virtual bool GoToStateCore(
  Control control, 
  FrameworkElement templateRoot, 
  string stateName, 
  VisualStateGroup group, 
  VisualState state, 
  bool useTransitions



Type: Control

The control to transition between states.


Type: FrameworkElement

The root element of the control's ControlTemplate.


Type: System.String [.NET] | Platform::String [C++]

The name of the state to transition to.


Type: VisualStateGroup

The VisualStateGroup that the state belongs to.


Type: VisualState

The representation of the state to transition to.


Type: System.Boolean [.NET] | Platform::Boolean [C++]

true to use a VisualTransition to transition between states; otherwise, false.

Return value

Type: System.Boolean [.NET] | Platform::Boolean [C++]

true if the control successfully transitions to the new state; otherwise, false.


This API is part of the scenario of defining a custom VisualStateManager behavior. Overriding GoToStateCore changes the state behavior in your custom class behavior.

To reference your custom VisualStateManager class, set the value of the VisualStateManager.CustomVisualStateManager attached property within any control template where you want to use the custom VisualStateManager class behavior. You typically create an instance of the custom VisualStateManager class through default XAML construction in Application.Resources. Then the VisualStateManager.CustomVisualStateManager attached property is set using a {StaticResource} markup extension reference to the key of the custom VisualStateManager resource.

Notes to inheritors

When a consumer of your custom VisualStateManager class calls GoToState to change the visual state of a control, this is the default behavior you are overriding:

If a VisualState for stateName doesn't exist in the group, your implementation should return false.

If the control is already in the VisualState requested as stateName, your implementation should return true.

For more info on the default behavior, see GoToState.

Events for visual state changes

CurrentStateChanging fires when the control begins to transition states as requested by the GoToState call. If a VisualTransition is applied to the state change, this event occurs when the transition begins.

CurrentStateChanged fires after the control is in the state as requested by the GoToState call, just as the new Storyboard begins. No event is fired on the new storyboard's completion.

If a VisualTransition is not applied, CurrentStateChanging and CurrentStateChanged fire in quick succession, but are guaranteed in that order if both occur.

However, if a state change transition is interrupted by a new GoToState call, the CurrentStateChanged event is never raised for the first state transition. A new event series is fired for the next requested state change.

Overriding the behavior of RaiseCurrentStateChanged and RaiseCurrentStateChanging is optional: how and when the events are raised by the default implementation might be adequate for your custom class.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml [C++]



See also

Quickstart: Control templates



© 2016 Microsoft