Template authors add VisualStateGroup objects the VisualStateManagerVisualStateGroups()()() attached property to represent states of a control and Control authors transition between states by calling the GoToState method.
If you want to implement your own logic for transitioning between states, you must inherit from VisualStateManager, override the GoToStateCore method, and set the VisualStateManager..::.CustomVisualStateManager attached property on the control that uses the custom logic.