次の方法で共有


IXRVisualStateGroup (Compact 2013)

3/28/2014

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

Syntax

class IXRVisualStateGroup : public IXRDependencyObject

Inheritance Hierarchy

IXRDependencyObject

    IXRVisualStateGroup

Methods

Method

Description

IXRVisualStateGroup::AddVisualStateChangedEventHandler

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

IXRVisualStateGroup::AddVisualStateChangingEventHandler

Attaches a delegate to the VisualStateChanging event for this visual state group. When the VisualStateChanging event occurs, this delegate is 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.

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

To specify the appearance and behavior of a control when it is in different states, by using C++ you can create IXRVisualState objects, and then combine them in IXRVisualStateCollections, which are assigned to an IXRVisualStateGroup. IXRVisualStateGroup is a member of an IXRVisualStateGroupCollection that is one of the following:

  • The value of an attached property of a content element of an IXRUserControl derived object.
  • The value of the VisualStatesGroups attached property of the VisualStateManager of the ControlTemplate for an IXRControl-derived object.

States that are mutually exclusive must be put into the same IXRVisualStateGroup. For example, an IXRCheckBox control has two visual state groups that are defined in Microsoft Silverlight 3 XAML. The group named CommonStates contains the states Normal, MouseOver, Pressed, and Disabled. The group named CheckStates 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 inherits from IXRControl, and has its own default visual states. You can modify the visual states for a control that inherits from IXRControl by creating a new ControlTemplate for that control in Silverlight 3 XAML. You cannot add states to or remove states from a control template. You cannot apply a ControlTemplate to a control that inherits from IXRUserControl.

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

You can also define a visual state group in Microsoft Silverlight 3 XAML, 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 VisualStateGroup Class on MSDN.

Note

The contents of a ControlTemplate defined in Microsoft Silverlight 3 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 XAML for Windows Embedded 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 illustrates how to add an existing visual state group to a user control. To run the 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.

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 "windows.h"
#include "XamlRuntime.h"
#include "XRPtr.h"

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

      // Create a new collection object
      IXRVisualStateGroupCollectionPtr pVisualStateGroups;
      pApplication->CreateObject(&pVisualStateGroups);

      // Add the visual state group to the new collection
      int* index = 0;
      pVisualStateGroups->Add(pGroup, index);

      // Create a new child element and set the new collection 
      // as the value of its VisualStateManager.VisualStateGroups attached property
       IXRFrameworkElementPtr pContent;
      pApplication->CreateObject(&pContent);

      pContent->SetAttachedProperty(L"VisualStateManager.VisualStateGroups", NULL, pVisualStateGroups);

      // Set the new child element as the content of the user control
      pUserControl->SetContent(pContent);

}

.NET Framework Equivalent

System.Windows.VisualStateGroup

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Visual Appearance