次の方法で共有


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の名前。

次の例では、CommonStates と呼ばれるButtonControlTemplateVisualStateGroupを作成し、状態、NormalPressed、およびMouseOverVisualState オブジェクトを追加します。 Buttonでは、CommonStatesVisualStateGroup内にある Disabled と呼ばれる状態も定義されますが、簡潔にするために省略しています。 例全体については、「コントロールの テンプレートを作成する方法」を参照してください。

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

注釈

VisualStateNameVisualStateManagerに渡すことで、要素が入力するビジュアル状態を指定します。

ControlControlTemplateVisualStateManagerを使用する場合、コントロールの作成者は、TemplateVisualStateAttributeをクラス シグネチャに配置することによって、コントロールがControlTemplateで見つけるオブジェクトVisualStateを指定する必要があります。 ControlTemplate 作成者は新しい VisualState オブジェクトを定義し、 Name プロパティを TemplateVisualStateAttribute.Name プロパティで指定された値に設定します。

WPF に含まれているコントロールの表示状態の名前については、「 コントロールのスタイルとテンプレート」を参照してください。 既存のコントロールの ControlTemplate オブジェクトと VisualState オブジェクトを作成する方法については、「 コントロールのテンプレートを作成する方法」を参照してください。

適用対象