Share via


VisualStateGroup.States Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the collection of mutually exclusive VisualState objects.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public ReadOnly Property States As IList
public IList States { get; }
<VisualStateGroup>
    oneOrMoreVisualStates
</VisualStateGroup>

XAML Values

  • oneOrMoreVisualStates
    One or more object elements that is of type VisualState.

States is the XAML content property of VisualStateGroup and can thus support this content element syntax, as opposed to having to specify object.States as a property element.

Property Value

Type: System.Collections.IList
The collection of mutually exclusive VisualState objects.

Examples

The following example creates a simple ControlTemplate for a Button that contains one Grid. It also contains a VisualStateGroup called CommonStates, which defines the MouseOver 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 mouse over the Button.

Run this sample

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

        <VisualStateGroup.Transitions>

          <!--Take one half second to trasition to the MouseOver state.-->
          <VisualTransition To="MouseOver" 
                              GeneratedDuration="0:0:0.5"/>
        </VisualStateGroup.Transitions>

        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            mouse is over the button.-->
        <VisualState x:Name="MouseOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
                            Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </Grid>
</ControlTemplate>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.