首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么此ColorAnimation不启动?

为什么此ColorAnimation不启动?
EN

Stack Overflow用户
提问于 2012-08-14 03:27:58
回答 1查看 156关注 0票数 2

我正在尝试让ColorAnimation根据控件的状态发生。我为ToggleButton创建了一个类似如下的ControlTemplate:

代码语言:javascript
复制
<ControlTemplate TargetType="ToggleButton">
    <Border>
    <Grid>
        <VisualStateManager.VisualStateGroup>
             <VisualStateGroup x:Name="CommonStates">
                  <VisualState x:Name="MouseOver">
                      <Storyboard>
                           <ColorAnimation Storyboard.TargetName="ColorChangeRect" 
                               Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)"
                               To="Blue" Duration="0:0:3" />
                      </Storyboard>
                  </VisualState>
             </VisualStateGroup>
        </VisualStateManager.VisualStateGroup>
        <Rectangle x:Name=ColorChangeRect" Fill="Red" />
        <ContentPresenter Content="{TemplateBinding Content}" />
    </Grid>
    </Border>
</ControlTemplate>

不幸的是,什么都没有发生。我不确定我错过了什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-14 03:36:28

VisualStateManager.VisualStateGroups附加属性放在模板的根元素上,即代码中的Border。这就是VisualStateManager获取状态的地方。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11940974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档