VisualState 类

定义

表示特定状态下控件的可视外观。Represents the visual appearance of the control when it is in a specific state.

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

示例

下面的示例VisualStateGroup ControlTemplateButtonPressed VisualState MouseOver Normal为的中创建一个, 并为状态、、和添加对象。 CommonStatesThe following example creates a VisualStateGroup in the ControlTemplate of a Button called CommonStates and adds VisualState objects for the states, Normal, Pressed, and MouseOver. 还定义了一个名Disabled为的状态VisualStateGroup, 在CommonStates中, 该示例为简洁起见省略了该状态。 ButtonThe Button also defines a state called Disabled that is in the CommonStatesVisualStateGroup, but the example omits it for brevity. 有关完整示例, 请参阅通过创建 System.windows.controls.controltemplate> 自定义现有控件的外观For the entire example, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate.

  <!--Define the states and transitions for the common states.
      The states in the VisualStateGroup are mutually exclusive to
      each other.-->
  <VisualStateGroup x:Name="CommonStates">

    <!--The Normal state is the state the button is in
        when it is not in another state from this VisualStateGroup.-->
    <VisualState x:Name="Normal" />

    <!--Change the SolidColorBrush, BorderBrush, to red when the
        mouse is over the button.-->
    <VisualState x:Name="MouseOver">
      <Storyboard>
        <ColorAnimation Storyboard.TargetName="BorderBrush" 
                        Storyboard.TargetProperty="Color" 
                        To="Red" />
      </Storyboard>
    </VisualState>

    <!--Change the SolidColorBrush, BorderBrush, to Transparent when the
        button is pressed.-->
    <VisualState x:Name="Pressed">
      <Storyboard>
        <ColorAnimation Storyboard.TargetName="BorderBrush" 
                        Storyboard.TargetProperty="Color"
                        To="Transparent"/>
      </Storyboard>
    </VisualState>

    <!--The Disabled state is omitted for brevity.-->
  </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

注解

VisualState指定控件在处于某种状态时的外观。A VisualState specifies how the control looks when it is in a certain state. 例如, 在按下Button时, 其边框可能不同于正常颜色。For example, when a Button is pressed, its border might be a different color than normal. 类具有一个Storyboard属性, 该属性更改控件的外观。 VisualStateThe VisualState class has a Storyboard property that changes the appearance of the control. 当控件输入VisualState.Name属性指定的状态时, 将Storyboard开始。When the control enters the state that is specified by the VisualState.Name property, the Storyboard begins. 当控件退出状态时, 将Storyboard停止。When the control exits the state, the Storyboard stops.

VisualStateGroup.States属性包含VisualState对象。The VisualStateGroup.States property contains VisualState objects. VisualStateGroup对象将添加到VisualStateManager.VisualStateGroupsFrameworkElement上定义的附加属性中。VisualStateGroup objects are added to the VisualStateManager.VisualStateGroups attached property, which is defined on the on a FrameworkElement. 您可以将VisualState对象添加到FrameworkElement任何对象, 但这些对象ControlTemplate通常Control用于的中。You can add VisualState objects to any FrameworkElement, but they are typically are used in a ControlTemplate of a Control. 有关如何为现有控件创建ControlTemplateVisualState对象的信息, 请参阅通过创建 system.windows.controls.controltemplate> 自定义现有控件的外观For information about how to create a ControlTemplate and VisualState objects for existing controls, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. 有关使用VisualState之外ControlTemplate的对象的示例, 请参阅VisualStateManager类。For an example of using VisualState objects outside of a ControlTemplate, see the VisualStateManager class.

构造函数

VisualState()

初始化 VisualState 类的新实例。Initializes a new instance of the VisualState class.

属性

DependencyObjectType

获取对此实例的 DependencyObjectType 类型进行包装的 CLRCLRGets the DependencyObjectType that wraps the CLRCLR type of this instance.

(继承自 DependencyObject)
Dispatcher

获取与此 Dispatcher 关联的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(继承自 DispatcherObject)
IsSealed

获取一个值,该值指示此实例当前是否为密封的(只读)。Gets a value that indicates whether this instance is currently sealed (read-only).

(继承自 DependencyObject)
Name

获取或设置 VisualState 的名称。Gets or sets the name of the VisualState.

Storyboard

获取或设置一个 Storyboard,它定义控件在 VisualState 所表示的状态下的外观。Gets or sets a Storyboard that defines the appearance of the control when it is in the state that is represented by the VisualState.

方法

CheckAccess()

确定调用线程是否可以访问此 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(继承自 DispatcherObject)
ClearValue(DependencyProperty)

清除属性的本地值。Clears the local value of a property. 要清除的属性由 DependencyProperty 标识符指定。The property to be cleared is specified by a DependencyProperty identifier.

(继承自 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只读属性的本地值。Clears the local value of a read-only property. 要清除的属性由 DependencyPropertyKey 指定。The property to be cleared is specified by a DependencyPropertyKey.

(继承自 DependencyObject)
CoerceValue(DependencyProperty)

对指定依赖属性的值进行强制。Coerces the value of the specified dependency property. 通过对调用方 CoerceValueCallback 上存在的依赖属性的属性元数据中所指定的任何 DependencyObject 函数进行调用来完成此操作。This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(继承自 DependencyObject)
Equals(Object)

确定提供的 DependencyObject 是否等效于当前 DependencyObjectDetermines whether a provided DependencyObject is equivalent to the current DependencyObject.

(继承自 DependencyObject)
GetHashCode()

获取此 DependencyObject 的哈希代码。Gets a hash code for this DependencyObject.

(继承自 DependencyObject)
GetLocalValueEnumerator()

创建一个专用的枚举数,用于确定哪些依赖项属性在此 DependencyObject 上具有以本地方式设置的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(继承自 DependencyObject)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetValue(DependencyProperty)

DependencyObject 的此实例返回依赖属性的当前有效值。Returns the current effective value of a dependency property on this instance of a DependencyObject.

(继承自 DependencyObject)
InvalidateProperty(DependencyProperty)

重新评估指定依赖属性的有效值。Re-evaluates the effective value for the specified dependency property.

(继承自 DependencyObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

每当更新此 DependencyObject 的任何依赖属性的有效值时调用。Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. 更改的特定依赖属性将在事件数据中报告。The specific dependency property that changed is reported in the event data.

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

如果存在,则返回依赖属性的本地值。Returns the local value of a dependency property, if it exists.

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

设置依赖属性的值而不更改其值源。Sets the value of a dependency property without changing its value source.

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

设置依赖属性的本地值,该值由其依赖属性标识符指定。Sets the local value of a dependency property, specified by its dependency property identifier.

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

设置一个只读依赖属性的本地值,该值由依赖属性的 DependencyPropertyKey 标识符指定。Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(继承自 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

返回一个值,该值指示序列化进程是否应序列化所提供的依赖属性的值。Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(继承自 DependencyObject)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
VerifyAccess()

强制调用线程具有此 DispatcherObject 的访问权限。Enforces that the calling thread has access to this DispatcherObject.

(继承自 DispatcherObject)

适用于