Partager via


IXRVisualStateGroup (Windows Embedded CE 6.0)

1/6/2010

This class contains mutually exclusive IXRVisualState objects, which define particular visual states, and IXRVisualTransition objects, which are applied when a user control goes from one state to another state.

Syntax

class IXRVisualStateGroup : public IXRDependencyObject

Methods

Method Description

IXRVisualStateGroup::AddVisualStateChangedEventHandler

Attaches a delegate to the VisualStateChanged event for this visual-state group. When the VisualStateChanged event occurs, this delegate will be invoked.

IXRVisualStateGroup::AddVisualStateChangingEventHandler

Attaches a delegate to the VisualStateChanging event for this visual-state group. When the VisualStateChanging event occurs, this delegate will be invoked.

IXRVisualStateGroup::GetTransitions

Retrieves the collection of mutually exclusive IXRVisualTransition objects that you added in IXRVisualStateGroup::SetTransitions.

IXRVisualStateGroup::GetStates

Retrieves the collection of mutually exclusive IXRVisualState objects that you set in IXRVisualStateGroup::SetStates.

IXRVisualStateGroup::RemoveVisualStateChangedEventHandler

Removes a delegate from the VisualStateChanged event for this visual-state group.

IXRVisualStateGroup::RemoveVisualStateChangingEventHandler

Removes a delegate from the VisualStateChanging event for this visual-state group.

IXRVisualStateGroup::SetTransitions

Sets the collection of mutually exclusive IXRVisualTransition objects for this visual-state group.

IXRVisualStateGroup::SetStates

Sets the collection of mutually exclusive IXRVisualState objects for this visual-state group.

Remarks

C++ developers can create IXRVisualState objects and add them to an IXRVisualStateGroup. This IXRVisualStateGroup is part of an IXRVisualStateGroupCollection that is set to the value an attached property of a child element of an IXRUserControl. By adding visual states to the content of a new user control, you can specify visual behavior of that control.

States that are mutually exclusive must be put in the same IXRVisualStateGroup. For example, an IXRCheckBox control has two visual-state groups that are defined in Microsoft Silverlight 2 XAML. One group contains the states Normal, MouseOver, Pressed, and Disabled. The other group contains the states Checked, Unchecked, and Indeterminate. An IXRCheckBox control can be in the states MouseOver and UnChecked at the same time. However, it cannot be in the MouseOver and Pressed states at the same time.

Note

An IXRCheckBox control does not inherit from IXRUserControl and has its own default visual states. You can provide custom visual states for a control that does not inherit from IXRUserControl by creating a style that has a ControlTemplate for that control in Silverlight 2 XAML.

You can also define a visual-state group in Microsoft Silverlight 2 XAML, in the source XAML that is parsed by your application. For information about the differences between XAML in Silverlight for Windows Embedded and Silverlight 2, see Differences Between Silverlight for the Web and Silverlight for Windows Embedded. For more information about how to define this element in the source XAML for your application, see this Microsoft Web site.

Note

The contents of a ControlTemplate defined in Microsoft Silverlight 2 XAML cannot be accessed from C++. Therefore, visual-state groups that were defined in a ControlTemplate in the source XAML for your application cannot be accessed in Silverlight object tree.

The collection retrieved by IXRVisualStateGroup::GetTransitions contains IXRVisualTransition objects that are applied when the control transitions between states that are defined in this IXRVisualStateGroup object.

Example

The following example code is a simple illustration of how to add an existing visual-state group to a user control.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

#include "stdafx.h"
#include "XamlRuntime.h"

AddVisualStateGroupToControl(IXRApplication* pApplication, IXRVisualStateGroup* pGroup, 
  IXRUserControl* pUserControl)
{

      // Create a new collection object
      IXRVisualStateGroupCollection* pVisualStateGroups;
      pApplication->CreateObject(IID_IXRVisualStateGroupCollection, &pVisualStateGroups);

      // Add the visual-state group to the new collection
      UINT* index;
      pVisualStateGroups->Add(pGroup, &index);

      // Create a child element and add the collection to it by  
      // setting a value for VisualStateManager.VisualStateGroups
      IXRFrameworkElement* pContent;
      pApplication->CreateObject(IID_IXRFrameworkElement, &pContent);
      pContent->SetAttachedProperty(L"VisualStateManager.VisualStateGroups", &pVisualStateGroups);

      // Add the child element to the user control
      pUserControl->AddContent(&pContent);

}

To run the previous code example, both an IXRVisualStateGroup object and an IXRVisualStateGroupCollection object must already be created. Additionally, an IXRUserControl object, to which this code adds the visual states, must already be created.

.NET Framework Equivalent

System.Windows.VisualStateGroup

Requirements

Header XamlRuntime.h
sysgen SYSGEN_XAML_RUNTIME
Windows Embedded CE Windows Embedded CE 6.0 R3

See Also

Reference

Classes for Visual Appearance and Behavior

Other Resources