Windows 8 Metro 控件的可能 VisualStates 记录在哪里? [英] Where are the possible VisualStates for Windows 8 Metro controls documented?

查看:17
本文介绍了Windows 8 Metro 控件的可能 VisualStates 记录在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When writing a custom ControlTemplate (XAML) for a Win 8 Metro control we need to use the VisualStateManager to update the control according to VisualState transitions. I see the below sample all over MSDN, but I can't find where the VisualStateGroup "CommonStates" is documented and what other VisualStates are defined other than "PointerOver" and "Normal"? Do you have to go dig in the SDK to find the default ControlTemplate for a button? If so, where?

<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 文件的设计视图并选择 Button 控件 - 右键单击​​/编辑模板/编辑当前 - 将为您提供默认模板提取.通常,控件应该使用属性进行注释,这些属性指示应该在模板中使用哪些视觉状态,如下所示,但是当我导航到像 Button 这样的控件的定义时,我看不到它们.

You can go to the design view of your xaml file and with the Button control selected - right click/Edit Template/Edit Current - will get you the default template extracted. Normally controls should be annotated with attributes that indicate which visual states should be used in the template like below, but I can't see them when I just navigate to definition of a control like Button.

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

这篇关于Windows 8 Metro 控件的可能 VisualStates 记录在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆