Manages states and the logic for transitioning between states for controls.
Assembly: PresentationFramework (in PresentationFramework.dll)
Gets a value that indicates whether this instance is currently sealed (read-only).(Inherited from DependencyObject.)
The Button might have a slightly different appearance when it is pressed than when it is not pressed. Two states that the Button defines correspond to when it is pressed ("Pressed") and when it is not ("Normal"). The appearance of a control when it is in a state is defined by a VisualState. A VisualState contains a collection of Storyboard objects that specify how the control's appearance changes when the control is in that state. You add visual states to a control by setting the VisualStateManager.VisualStateGroups attached property on the control. Each VisualStateGroup contains a collection of VisualState objects that are mutually exclusive. That is, the control is always in exactly one state of in each VisualStateGroup.enables you to specify states for a control, the appearance of a control when it is in a certain state, and when a control changes states. For example, a
The ControlTemplate, call the GoToState method. For more information about how to create controls that use the , see Creating a Control That Has a Customizable Appearance. If you use the outside of a ControlTemplate (for example, if you use a in a UserControl or in a single element), call the GoToElementState method. In either case, the performs the logic that is required to appropriately start and stop the storyboards that are associated with the involved state. For example, suppose that a control defines the states, State1 and State2, each of which has a storyboard associated with it. If the control is in State1 and you pass State2 to GoToState or GoToElementState, the starts the storyboard in State2 and stops the storyboard in State1.also enables you to specify when a control enters a specific state. The method that you should call to change states depends on your scenario. If you create a control that uses the in its
Controls that are included with Windows Presentation Foundation (WPF) use the ControlTemplate for a control that is included with WPF, you can add VisualState objects to the control's ControlTemplate to specify the control's appearance in a certain state. To find the names of the visual states for the controls that are included with WPF, see Control Styles and Templates. The control's logic handles transitioning between states, so you do not need to do anything other than define the VisualState objects in the new ControlTemplate. For more information about how to create control templates for existing controls, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate.to change visual states. When you create a
If you want to implement your own logic for transitioning between states, you must inherit from GoToStateCore method, and set the VisualStateManager.CustomVisualStateManager attached property on the control that uses the custom logic., override the
The following example creates a Rectangle and adds a VisualStateGroup named CommonStates to the VisualStateManager.VisualStatesGroups attached property. The example defines the MouseOver and NormalVisualState objects in the CommonStatesVisualStateGroup. When the user moves the mouse pointer over the Rectangle, it changes from red to green over one half second. When the user moves the mouse away from the rectangle, the Grid immediately changes back to red. Note that the Normal state does not define a Storyboard. A Storyboard is not required because when the Rectangle transitions from the MouseOver state to the Normal state, the Storyboard for MouseOver is stopped and the Color property for the SolidColorBrush returns to red.
The following example shows the event handler that is defined in the previous example and calls the GoToElementState method to transition between states. If the rectangle in the previous example was part of a ControlTemplate, the example would have to call the GoToState method.
Available since 4.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.