次の方法で共有


IXRVisualState (Compact 2013)

3/28/2014

This class represents the visual appearance of the control when it is in a specific state.

Syntax

class IXRVisualState : public IXRDependencyObject

Inheritance Hierarchy

IXRDependencyObject

    IXRVisualState

Methods

Method

Description

IXRVisualState::GetStoryboard

Retrieves an IXRStoryboard that defines the appearance of the control when it is in the state that this IXRVisualState represents.

IXRVisualState::SetStoryboard

Sets an IXRStoryboard that defines the appearance of the control when it is in the state that this IXRVisualState represents.

Thread Safety

Members of this class are thread-safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

Remarks

An IXRVisualState object specifies how a control appears when it is in a certain state.

Visual states are predefined in the templates of many controls that derive from the IXRControl class. IXRButton and IXRTextBox are controls with ControlTemplates, which contain predefined visual states (see Control Styles and Templates on MSDN). For example, when a button is pressed, its border might be a different color than usual.

To change or define visual states for a control derived from the IXRControl class, define and apply a new ControlTemplate to the control. You cannot add states to or remove states from ControlTemplate; you can only define the appearance of those states and define the transition behavior between states.

Note

The contents of a ControlTemplate defined in Microsoft Silverlight 3 XAML cannot be accessed from C++. Therefore, visual state groups that are defined in a control template in the source XAML for your application cannot be accessed in XAML for Windows Embedded object tree.

A user control is a custom control that derives from the IXRUserControl class and has no predefined states. You cannot apply a ControlTemplate to a user control even though the IXRUserControl class inherits from the IXRControl class. If you are working with a user control, you can add and remove states, and define their appearance and the transition behavior between the states.

Use the IXRVisualState::SetStoryboard method to change the appearance of the control by providing an animation timeline that changes properties to new values for a specific state. After you create a new IXRVisualState object and provide a state name, you can customize the visual appearance of that state by calling IXRVisualState::SetStoryboard and providing a new IXRStoryboard object.

When the control enters the state that is specified by its name, the storyboard animation begins. When the control exits the state, the storyboard animation for the new state begins.

The state name can be retrieved or set by using the inherited methods IXRDependencyObject::GetName and IXRDependencyObject::SetName. The state name is used by the IXRControl::GoToVisualState method to change the state of the control.

A collection of mutually exclusive IXRVisualState objects is stored in an IXRVisualStateCollection. This collection is assigned to an IXRVisualStateGroup object, and can be accessed by using IXRVisualStateGroup::GetStates. The control cannot simultaneously be in more than one state from a given visual state group, but can simultaneously be in states from separate visual state groups.

A collection of visual state groups, represented by IXRVisualStateGroupCollection, can be accessed through an attached property on an IXRFrameworkElement child element of an IXRUserControl. The attached property is called VisualStateManager.VisualStateGroups.

Use the following procedure to define visual states for a user control that does not already contain a visual state group collection.

  1. Create one or more new IXRVisualState objects and a new IXRVisualStateCollection.
  2. Add the IXRVisualState objects to the IXRVisualStateCollection by calling the IXRVisualStateCollection::Add method.
  3. Create a new IXRVisualStateGroup object, and add the new collection to it by calling IXRVisualStateGroup::SetStates.
  4. Create a new IXRVisualStateGroupCollection object, and add the IXRVisualStateGroup object to it by calling its inherited method IXRVisualStateGroupCollection::Add.
  5. Create a new IXRFrameworkElement root element to represent a new child element for the control.
  6. On the IXRFrameworkElement object, call IXRDependencyObject::SetAttachedProperty(const WCHAR*, const WCHAR*, IXRDependencyObject*) and set the IXRVisualStateGroupCollection object as the VisualStateManager.VisualStateGroups attached-property value.
  7. After the visual states are added to the IXRFrameworkElement root element, add the root element to the user control by calling IXRUserControl::SetContent.

When you create a class instance, use an IXRVisualStatePtr smart pointer instead of a raw interface pointer. For more information, see XRPtr<Interface>.

You can also define a visual state in Microsoft Silverlight 3 XAML, in the source XAML that your application parses. For information about the differences between XAML in XAML for Windows Embedded and Silverlight 3, see Differences Between Microsoft Silverlight 3 and XAML for Windows Embedded. For more information about how to define this element in the source XAML for your application, see VisualState Class on MSDN.

Note

The contents of a ControlTemplate defined in Microsoft Silverlight 3 XAML cannot be accessed from C++. Therefore, visual states and visual state groups that were defined in a ControlTemplate in your application's source XAML cannot be accessed in the XAML for Windows Embedded object tree.

.NET Framework Equivalent

System.Windows.VisualState

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Visual Appearance