Uredi

Deli z drugimi prek


VisualState.Name Property

Definition

Gets or sets the name of the 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

Property Value

The name of the VisualState.

Examples

The following example creates a VisualStateGroup in the ControlTemplate of a Button called CommonStates and adds VisualState objects for the states, Normal, Pressed, and MouseOver. The Button also defines a state called Disabled that is in the CommonStates VisualStateGroup, but the example omits it for brevity. 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>

Remarks

You specify which visual state an element should enter by passing the Name of the VisualState to the VisualStateManager.

When a Control uses the VisualStateManager in a ControlTemplate, the control author should specify which VisualState objects the control expects to find in its ControlTemplate by putting the TemplateVisualStateAttribute on its class signature. ControlTemplate authors define new VisualState objects and set the Name property to the value specified by the TemplateVisualStateAttribute.Name property.

To find the names of the visual states for the controls that are included with WPF, see Control Styles and Templates. 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.

Applies to