VisualStateGroup 类

定义

包含互斥的 VisualState 对象和用于从一种状态转移到另一种状态的 VisualTransition 对象。

public ref class VisualStateGroup : System::Windows::DependencyObject
[System.Windows.Markup.ContentProperty("States")]
[System.Windows.Markup.RuntimeNameProperty("Name")]
public class VisualStateGroup : System.Windows.DependencyObject
[<System.Windows.Markup.ContentProperty("States")>]
[<System.Windows.Markup.RuntimeNameProperty("Name")>]
type VisualStateGroup = class
    inherit DependencyObject
Public Class VisualStateGroup
Inherits DependencyObject
继承
属性

示例

以下示例为包含一GridButton实例的简单ControlTemplate方法创建一个。 它还包含一个 VisualStateGroup 命名, CommonStates用于定义 MouseOverNormal 状态。 VisualStateGroup此外,还有一个VisualTransition指定当用户将鼠标指针移到鼠标指针上方Button时,将鼠标指针从绿色更改为红色需要半秒Grid的时间。

<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>

注解

每个 VisualStateGroup 对象都包含一个 VisualState 对象集合。 一 VisualState 个对象集合,该集合 Storyboard 指定控件在控件处于特定状态时控件的外观更改方式。 例如, Button 当按下时,它的外观可能略有不同,而不是按下时。 定义 Button 对应于按下 ("Pressed") 时和未 () "Normal" 时的两个状态。

通过在控件上设置VisualStateManager.VisualStateGroups附加属性来添加到VisualState控件。 将相互排斥的状态放在同一 VisualStateGroup个状态中。 例如,有 CheckBox 两个 VisualStateGroup 对象。 一个包含状态、NormalMouseOver``PressedDisabled。 另一个包含状态、Checked``UnChecked状态和 Indeterminate。 可以CheckBox同时处于状态MouseOver``UnChecked,但它不能同时处于MouseOver状态和Pressed状态。

尽管可以将对象添加到 VisualState 任何元素,但它们是一种特别有用的方法,使其他人能够重新定义对象的 Control视觉行为。 如果创建自定义控件, ControlTemplate则可以通过在其类定义中添加一个 TemplateVisualStateAttribute 状态来指定控件可以处于哪个状态。 然后,为控件创建新 ControlTemplate 对象的任何人都可以将对象添加到 VisualState 模板。 这使 TemplateVisualStateAttribute 设计器工具(如 Visual Studio 和 Blend for Visual Studio)能够公开控件的状态。 具有相同 TemplateVisualStateAttribute.GroupName 的州属于同一 VisualStateGroup个。

有关如何使用对象的详细信息,请参阅通过创建 ControlTemplate 自定义现有控件的外观ControlTemplateVisualStateGroup 有关如何创建使用该 VisualStateManager控件的详细信息,请参阅 创建具有可自定义外观的控件

Transitions 属性包含 VisualTransition 当控件在定义 VisualStateGroup状态之间切换时应用的对象。

构造函数

VisualStateGroup()

初始化 VisualStateGroup 类的新实例。

属性

CurrentState

获取当前应用到该控件的 VisualState

DependencyObjectType

获取包装 DependencyObjectType 此实例的 CLR 类型。

(继承自 DependencyObject)
Dispatcher

获取与此 Dispatcher 关联的 DispatcherObject

(继承自 DispatcherObject)
IsSealed

获取一个值,该值指示此实例当前是否为密封的(只读)。

(继承自 DependencyObject)
Name

获取或设置 VisualStateGroup 的名称。

States

获取互斥 VisualState 对象的集合。

Transitions

获取 VisualTransition 对象的集合。

方法

CheckAccess()

确定调用线程是否可以访问此 DispatcherObject

(继承自 DispatcherObject)
ClearValue(DependencyProperty)

清除属性的本地值。 要清除的属性由 DependencyProperty 标识符指定。

(继承自 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只读属性的本地值。 要清除的属性由 DependencyPropertyKey 指定。

(继承自 DependencyObject)
CoerceValue(DependencyProperty)

对指定依赖属性的值进行强制。 通过对调用方 DependencyObject 上存在的依赖属性的属性元数据中所指定的任何 CoerceValueCallback 函数进行调用来完成此操作。

(继承自 DependencyObject)
Equals(Object)

确定提供的 DependencyObject 是否等效于当前 DependencyObject

(继承自 DependencyObject)
GetHashCode()

获取此 DependencyObject 的哈希代码。

(继承自 DependencyObject)
GetLocalValueEnumerator()

创建一个专用的枚举数,用于确定哪些依赖项属性在此 DependencyObject 上具有以本地方式设置的值。

(继承自 DependencyObject)
GetType()

获取当前实例的 Type

(继承自 Object)
GetValue(DependencyProperty)

DependencyObject 的此实例返回依赖属性的当前有效值。

(继承自 DependencyObject)
InvalidateProperty(DependencyProperty)

重新评估指定依赖属性的有效值。

(继承自 DependencyObject)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

每当更新此 DependencyObject 的任何依赖属性的有效值时调用。 更改的特定依赖属性将在事件数据中报告。

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

如果存在,则返回依赖属性的本地值。

(继承自 DependencyObject)
SetCurrentValue(DependencyProperty, Object)

设置依赖属性的值而不更改其值源。

(继承自 DependencyObject)
SetValue(DependencyProperty, Object)

设置依赖属性的本地值,该值由其依赖属性标识符指定。

(继承自 DependencyObject)
SetValue(DependencyPropertyKey, Object)

设置一个只读依赖属性的本地值,该值由依赖属性的 DependencyPropertyKey 标识符指定。

(继承自 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

返回一个值,该值指示序列化进程是否应序列化所提供的依赖属性的值。

(继承自 DependencyObject)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
VerifyAccess()

强制调用线程具有此 DispatcherObject 的访问权限。

(继承自 DispatcherObject)

事件

CurrentStateChanged

在控件转换为其他状态后发生。

CurrentStateChanging

在控件开始向其他状态转换时发生。

适用于