Name property
Collapse the table of content
Expand the table of content

VisualState.Name property

Gets the name of the VisualState.


public string Name { get; }

<VisualState x:Name="stateName"/>

XAML Values


The name of the VisualState. Name is a read-only property. You specify the name of the VisualState by setting the x:Name attribute. An unprefixed string "Name" won't work.

Property value

Type: System.String [.NET] | Platform::String [C++]

The name of the VisualState.


Name is a read-only property that you can check with code at run-time to read the value of the x:Name attribute that was applied to a VisualState in a XAML control template. You can't literally set Name because it's read-only, and x:Name attribute can only be set in XAML. The value is available as soon as the XAML that contains the control template and the VisualState definition is loaded.

The need to check the Name of a VisualState at run-time is anticipated to be relatively uncommon, and would only be relevant to advanced scenarios. For the most part, the definition of a VisualState in XAML combined with using VisualStateManager and VisualStateGroup events in code provides you all that you need to define and invoke visual states for a custom or Windows Runtime-defined control.


This example shows the correct way to name a VisualState, which is done by setting the x:Name attribute. This example creates a VisualStateGroup in the ControlTemplate of a Button called "CommonStates" and adds VisualState objects for the states, "Normal", "Pressed", and "PointerOver". The Button also defines a state called "Disabled" that is in the "CommonStates" named VisualStateGroup, but the example omits it for brevity.

<ControlTemplate TargetType="Button">
  <Border x:Name="RootElement">


      <!--Define the states 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
            Pointer is over the button.-->
        <VisualState x:Name="PointerOver">
            <ColorAnimation Storyboard.TargetName="BorderBrush" 
                              Storyboard.TargetProperty="Color" To="Red" />



        <!--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"/>
          <!--The Disabled state is omitted for brevity.-->

      <SolidColorBrush x:Name="BorderBrush" Color="Black"/>

    <Grid Background="{TemplateBinding Background}" Margin="4">
        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
        Margin="4,5,4,4" />



Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml [C++]



See also

x:Name attribute



© 2016 Microsoft