VisualStateGroup Class


Contains mutually exclusive VisualState objects and VisualTransition objects that are used to go from one state to another.

Equivalent WinUI class: Microsoft.UI.Xaml.VisualStateGroup.

public ref class VisualStateGroup sealed : DependencyObject
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.UI.Xaml.Markup.ContentProperty(Name="States")]
class VisualStateGroup final : DependencyObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.UI.Xaml.Markup.ContentProperty(Name="States")]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class VisualStateGroup final : DependencyObject
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class VisualStateGroup : DependencyObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class VisualStateGroup : DependencyObject
Public NotInheritable Class VisualStateGroup
Inherits DependencyObject
   <VisualStateGroup x:Name="groupname" ...>
   <!--- other peer VisualStateGroup's here ... -->

Windows 10 requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)


This example creates a simple ControlTemplate for a Button that contains one Grid. It also contains a VisualStateGroup called "CommonStates", which defines the "PointerOver" and "Normal" states. The VisualStateGroup also has a VisualTransition that specifies that it takes one half second for the Grid to change from green to red when the user puts the pointer over the Button.

<ControlTemplate TargetType="Button">
  <Grid >
      <VisualStateGroup x:Name="CommonStates">


          <!--Take one half second to transition to the PointerOver state.-->
          <VisualTransition To="PointerOver" 
        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            Pointer is over the button.-->
        <VisualState x:Name="PointerOver">
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
                            Storyboard.TargetProperty="Color" To="Red" />
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>


Each VisualStateGroup declared in XAML as part of a control template should always have an x:Name attribute set on it. Each name string used in the set of VisualStateGroups in a control template must be unique in that template. It's common to use the same group names for different controls though. For example, almost all existing control templates have a VisualStateGroup with x:Name attribute of "CommonStates".

The set of visual states within each VisualStateGroup should be mutually exclusive in the group. In other words, the control should be using exactly one of the visual states from each of its defined VisualStateGroup groups at all times. Whenever there's a case where a control is intended to be simultaneously in two states, make sure that the two states are in different groups. For example, it's possible for a drop-down control to simultaneously be focused and have its drop-down open. In a correct visual state design, you'd have a separate VisualStateGroup for each state so they can both be active at once. Such groups might have names like "FocusStates" and "DropDownStates".

Whenever you define a VisualStateGroup that enables a temporary storyboarded behavior in one of its VisualState elements, make sure that group also contains a second VisualState that can be called to cancel the previous state. This can be as simple as declaring the second VisualState with no Storyboard at all, just an x:Name attribute.

The x:Name attribute value you set for a VisualStateGroup is not used for a call to VisualStateManager.GoToState; instead it's the x:Name attribute of a VisualState that is used for VisualStateManager.GoToState. Anyone that uses VisualStateManager.GoToState should be aware of all the groups and states available, so that each call correctly transitions from old states to new states within a group.

In addition to a set of VisualState elements, a VisualStateGroup can also define a set of VisualTransition elements, where each VisualTransition pertains to at least one of the named VisualState elements defined in the group. In XAML, the set of VisualState elements can be declared as immediate object element child elements of the VisualStateGroup. This is possible because the States property, which is the collection of visual states, is the XAML content property for VisualStateGroup. In contrast, to set the collection of visual transitions, you must declare that collection within a VisualStateGroup.Transitions property element in XAML. For more info on XAML content properties, see XAML syntax guide.

When using StateTriggers to control visual states, the trigger engine uses the following precedence rules to score triggers and determine which trigger, and the corresponding VisualState, will be active:

  1. Custom trigger that derives from StateTriggerBase
  2. AdaptiveTrigger activated due to MinWindowWidth
  3. AdaptiveTrigger activated due to MinWindowHeight

If there are multiple active triggers at a time that have a conflict in scoring (i.e. two active custom triggers), then the first one declared in the markup file takes precedence.

Note: While AdaptiveTrigger does derive from StateTriggerBase, it can only be activated through setting MinWindowWidth and/or MinWindowHeight.

VisualStateGroup API that support custom VisualStateManager implementation

Many of the API of VisualStateGroup exist only to support custom VisualStateManager implementation. These include: Name, CurrentState, CurrentStateChanging, CurrentStateChanged. Most common usages of visual states for control templates won't need these API. In particular it's not typical to handle the events. Most logic operations for a control should involve its own properties and events. For most app and control definition scenarios, visual state changes that happen to the control should only be an end result of logic that the control applies to its template, not a trigger for other logic.



Initializes a new instance of the VisualStateGroup class.

Equivalent WinUI constructor: Microsoft.UI.Xaml.VisualStateGroup.VisualStateGroup.



Gets the most recently set VisualState from a successful call to the GoToState method.

Equivalent WinUI property: Microsoft.UI.Xaml.VisualStateGroup.CurrentState.


Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread.

Equivalent WinUI property: Microsoft.UI.Xaml.DependencyObject.Dispatcher.

(Inherited from DependencyObject)

Gets the name of the VisualStateGroup.

Equivalent WinUI property: Microsoft.UI.Xaml.VisualStateGroup.Name.


Gets the collection of mutually exclusive VisualState objects.

Equivalent WinUI property: Microsoft.UI.Xaml.VisualStateGroup.States.


Gets the collection of VisualTransition objects.

Equivalent WinUI property: Microsoft.UI.Xaml.VisualStateGroup.Transitions.



Clears the local value of a dependency property.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.ClearValue.

(Inherited from DependencyObject)

Returns any base value established for a dependency property, which would apply in cases where an animation is not active.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.GetAnimationBaseValue.

(Inherited from DependencyObject)

Returns the current effective value of a dependency property from a DependencyObject.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.GetValue.

(Inherited from DependencyObject)

Returns the local value of a dependency property, if a local value is set.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.ReadLocalValue.

(Inherited from DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.RegisterPropertyChangedCallback.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object)

Sets the local value of a dependency property on a DependencyObject.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.SetValue.

(Inherited from DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.UnregisterPropertyChangedCallback.

(Inherited from DependencyObject)



Occurs after a control changes into a different state.

Equivalent WinUI event: Microsoft.UI.Xaml.VisualStateGroup.CurrentStateChanged.


Occurs when a control begins changing into a different state.

Equivalent WinUI event: Microsoft.UI.Xaml.VisualStateGroup.CurrentStateChanging.

Applies to

See also