

Then you can call GoToState on your UserControl and apply states regardless of whether the rest of the content is a Control. We recommend you define a custom UserControl to either be the Window.Content root or be a container for other content you want to apply states to (such as a Panel ). Page is a Control subclass, and it's fairly rare that you'd be showing UI in a context where you don't have a Page, or your Window.Content root isn't a Control subclass. You can't do this directly because the control parameter of the GoToState method requires a Control subclass, which refers to the object that the VisualStateManager acts upon. Visual states are sometimes useful for scenarios where you want to change the state of some area of UI that's not immediately a Control subclass. It's more common for control definition code to do this rather than app code, so that all the possible visual states and their transitions and trigger conditions are there by default for app code, and the logic is encapsulated by the control.

Control authors do this whenever the control logic handles events that indicate a change of state, or control logic initiates a state change by itself. Control authors or app developers transition between these states by calling the static GoToState method of VisualStateManager.

For more info on how to write visual states in XAML, including example code, see Storyboarded animations for visual states. This Storyboard targets individual dependency property value changes that should be applied whenever the control is in that visual state. A VisualState consists mainly of a Storyboard. Each VisualState has a name that is representative of a UI state that can be changed by the user, or changed by control logic. Within a VisualStateGroup element, each VisualState represents a discrete visual state of a control. Control authors or app developers add VisualStateGroup object elements to the root element of a control template definition in XAML, using the VisualStateManager.VisualStateGroups attached property.VisualStateManager supports two important features for control authors, and for app developers who are applying a custom template to a control:
