通过


VisualState.Name 属性

定义

获取或设置 . 的名称 VisualState

public:
 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String

属性值

VisualState的名称。

示例

以下示例在已调用的集合中创建一个VisualStateGroupButton,并添加VisualState状态、NormalPressedMouseOver对象的对象。ControlTemplateCommonStates 该示例还定义了一个称为<a0/>的状态,但该示例为简洁起见省略该状态。 有关整个示例,请参阅 如何为控件创建模板

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

注解

通过向 传递 NameVisualStateVisualStateManager元素,可以指定元素应输入的视觉状态。

使用 in 时,控件作者应指定控件希望通过ControlTemplate在其TemplateVisualStateAttribute类签名上查找的对象VisualStateControlTemplateVisualStateManagerControl ControlTemplate 作者定义新 VisualState 对象,并将 Name 属性设置为属性指定的 TemplateVisualStateAttribute.Name 值。

若要查找 WPF 附带的控件的视觉状态的名称,请参阅 控件样式和模板。 有关如何为现有控件创建 ControlTemplate 对象的信息 VisualState ,请参阅 如何为控件创建模板

适用于