VisualState 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示特定状态下控件的可视外观。
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
- 继承
- 属性
示例
以下示例在调用项中创建一个VisualStateGroupButton,CommonStates
并为状态、Pressed``Normal
和添加VisualStateMouseOver
对象。ControlTemplate The Button also defines a state called Disabled
that is in the CommonStates
VisualStateGroup, but the example omits it for brevity. 有关整个示例,请参阅 通过创建 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 附加属性中,该属性在 on 上 FrameworkElement定义。 你可以将对象添加到VisualState任何FrameworkElement对象,但它们通常用于其中一个ControlTemplateControl对象。 有关如何为现有控件创建 ControlTemplate 和 VisualState 对象的信息,请参阅 通过创建 ControlTemplate 自定义现有控件的外观。 有关在外部ControlTemplate使用VisualState对象的示例,请参阅VisualStateManager该类。
构造函数
VisualState() |
初始化 VisualState 类的新实例。 |
属性
DependencyObjectType |
获取包装 DependencyObjectType 此实例的 CLR 类型。 (继承自 DependencyObject) |
Dispatcher |
获取与此 Dispatcher 关联的 DispatcherObject。 (继承自 DispatcherObject) |
IsSealed |
获取一个值,该值指示此实例当前是否为密封的(只读)。 (继承自 DependencyObject) |
Name |
获取或设置 VisualState 的名称。 |
Storyboard |
获取或设置一个 Storyboard,它定义控件在 VisualState 所表示的状态下的外观。 |