7

Win 8 Metroコントロール用のカスタムControlTemplate(XAML)を作成する場合、VisualStateManagerを使用してVisualState遷移に従ってコントロールを更新する必要があります。以下のサンプルはMSDN全体で見られますが、VisualStateGroupの「CommonStates」が文書化されている場所と、「PointerOver」と「Normal」以外に定義されている他のVisualStateが見つかりません。ボタンのデフォルトのControlTemplateを見つけるために、SDKを掘り下げる必要がありますか?もしそうなら、どこ?

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

        <VisualStateGroup.Transitions>

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

        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            Pointer is over the button.-->
        <VisualState x:Name="PointerOver">
          <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>
4

1 に答える 1

7

xamlファイルのデザインビューに移動し、ボタンコントロールを選択した状態で(右クリック/テンプレートの編集/現在の編集)、デフォルトのテンプレートが抽出されます。通常、コントロールには、以下のようにテンプレートで使用する視覚的な状態を示す属性を付ける必要がありますが、Buttonのようなコントロールの定義に移動すると、それらが表示されません。

[TemplateVisualState(GroupName="CommonStates", Name="Normal")]
[TemplateVisualState(GroupName="CommonStates", Name="PointerOver")]
于 2012-05-03T21:25:16.153 に答える