VisualState 类

定义

表示特定状态下控件的可视外观。

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

示例

以下示例VisualStateGroup在 名为 CommonStatesButton 中创建 ControlTemplate ,并为状态 NormalPressedMouseOver添加 VisualState 对象。 还 Button 定义了一个名为 Disabled 的状态,该状态位于 中 CommonStatesVisualStateGroup,但为了简洁起见,本示例省略了它。 有关整个示例,请参阅 通过创建 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 控件处于特定状态时的外观。 例如,按下 时 Button ,其边框的颜色可能与正常颜色不同。 类 VisualState 具有更改 Storyboard 控件外观的属性。 当控件进入 由 VisualState.Name 属性指定的状态时, Storyboard 开始。 当控件退出状态时,将 Storyboard 停止。

属性 VisualStateGroup.States 包含 VisualState 对象。 VisualStateGroup 对象将添加到 VisualStateManager.VisualStateGroups 附加属性中,该属性在 上的 FrameworkElement上定义。 可以将 对象添加到VisualState任何 FrameworkElement,但它们通常用于 的 ControlControlTemplate 有关如何为现有控件创建 ControlTemplateVisualState 对象的信息,请参阅 通过创建 ControlTemplate 自定义现有控件的外观。 有关在 外部ControlTemplate使用 VisualState 对象的示例,VisualStateManager请参阅 类。

构造函数

VisualState()

初始化 VisualState 类的新实例。

属性

DependencyObjectType

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

(继承自 DependencyObject)
Dispatcher

获取与此 Dispatcher 关联的 DispatcherObject

(继承自 DispatcherObject)
IsSealed

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

(继承自 DependencyObject)
Name

获取或设置 VisualState 的名称。

Storyboard

获取或设置一个 Storyboard,它定义控件在 VisualState 所表示的状态下的外观。

方法

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)

适用于