【问题标题】:Where are the possible VisualStates for Windows 8 Metro controls documented?Windows 8 Metro 控件可能的 VisualStates 记录在哪里?
【发布时间】:2012-05-03 04:25:39
【问题描述】:

在为 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>

【问题讨论】:

标签: xaml windows-8 windows-runtime winrt-xaml


【解决方案1】:

您可以转到 xaml 文件的设计视图并选择 Button 控件 - 右键单击​​/编辑模板/编辑当前 - 将为您提取默认模板。通常,控件应使用属性进行注释,这些属性指示应在模板中使用哪些视觉状态,如下所示,但当我只是导航到按钮等控件的定义时,我看不到它们。

[TemplateVisualState(GroupName="CommonStates", Name="Normal")]
[TemplateVisualState(GroupName="CommonStates", Name="PointerOver")]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 2014-03-26
    相关资源
    最近更新 更多