VisualStateManager.GoToStateCore method

Applies to Windows and Windows Phone

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

Syntax


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

Parameters

control

Type: Control

The control to transition between states.

templateRoot

Type: FrameworkElement

The root element of the control's ControlTemplate.

stateName

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

The name of the state to transition to.

group

Type: VisualStateGroup

The VisualStateGroup that the state belongs to.

state

Type: VisualState

The representation of the state to transition to.

useTransitions

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.

Remarks

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 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

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

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

Metadata

Windows.winmd

See also

VisualStateManager
GoToState
Quickstart: Control templates

 

 

Show:
© 2014 Microsoft. All rights reserved.