在为 Win 8 Metro 控件编写自定义 ControlTemplate (XAML) 时,我们需要使用 VisualStateManager 根据 VisualState 转换来更新控件。我在 MSDN 上看到了下面的示例,但我找不到 VisualStateGroup“CommonStates”的记录位置以及除了“PointerOver”和“Normal”之外还定义了哪些其他 VisualStates?您是否必须深入 SDK 才能找到按钮的默认 ControlTemplate?如果有,在哪里?
<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>