VisualStateManager.VisualStateGroups 添付プロパティ

定義

VisualStateGroup オブジェクトのコレクションを取得または設定します。

see GetVisualStateGroups
see GetVisualStateGroups
see GetVisualStateGroups

次の例では、1 つGridを含む a Button の単純なControlTemplateオブジェクトを作成します。 また、状態と状態を VisualStateGroup 定義する名前付き CommonStatesMouseOverNormal まれています。 また VisualStateGroup 、ユーザーがマウス ポインターを VisualTransition 上に移動したときに緑から赤に変わるのに 1/2 秒 Grid かかることを指定する Buttona もあります。

<ControlTemplate TargetType="Button">
  <Grid >
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">

        <VisualStateGroup.Transitions>

          <!--Take one half second to trasition to the MouseOver state.-->
          <VisualTransition To="MouseOver" 
            GeneratedDuration="0:0:0.5"/>
        </VisualStateGroup.Transitions>

        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            mouse is over the button.-->
        <VisualState x:Name="MouseOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
              Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </Grid>
</ControlTemplate>

注釈

それぞれに VisualStateGroup オブジェクトの VisualState コレクションが含まれています。 A VisualState には、コントロールが特定の Storyboard 状態のときにコントロールの外観がどのように変化するかを指定するオブジェクトのコレクションが含まれます。 たとえば、押 Button された場合と押されていない場合の外観が若干異なる場合があります。 定義が Button () 押されたとき"Pressed"と () でない"Normal"場合に対応する 2 つの状態。

コントロールに追加 VisualState するには、コントロールに VisualStateGroups 添付プロパティを設定します。 相互に排他的な状態を同じ VisualStateGroupに配置します。 たとえば、 CheckBox 2 つの VisualStateGroup オブジェクトがあります。 1 つには、状態、、NormalPressed``MouseOverおよび Disabled. もう 1 つには、状態、 Checked、、 UnCheckedおよび Indeterminate. 状態CheckBoxUnChecked同時に指定MouseOverできますが、同時にMouseOver状態とPressed状態にすることはできません。

任意の要素にオブジェクトを追加 VisualState できますが、他のユーザー Controlが . を使用 ControlTemplateするカスタム コントロールを作成する場合は、そのクラス定義に追加することで、コントロールを含めることができる状態を TemplateVisualStateAttribute 指定できます。 その後、コントロールの新 ControlTemplate しいオブジェクトを作成するすべてのユーザーが、テンプレートにオブジェクトを追加 VisualState できます。 同じ状態は同じSystem.Windows.TemplateVisualStateAttribute.GroupNameVisualStateGroupに属します。

オブジェクトの使用方法VisualStateGroupの詳細については、「ControlTemplate を作成して既存のコントロールの外観をカスタマイズする」を参照してください。ControlTemplate を使用 VisualStateManagerするコントロールを作成する方法の詳細については、「 カスタマイズ可能な外観を持つコントロールの作成」を参照してください。

適用対象