【发布时间】:2013-03-11 13:46:38
【问题描述】:
我正在开发一个 Windows Phone 8 项目。我对这个按钮的问题:
<Button x:Name="decreaseFontButton" Foreground="{StaticResource GlobalBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Height" Storyboard.TargetName="decreaseFontButton">
<DiscreteObjectKeyFrame KeyTime="0" Value="70"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="decreaseFontButton" Completed="ObjectAnimationUsingKeyFrames_Completed_1">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GlobalBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Button.Content>
<Image Source="/Assets/Player/sub_minus.png" Width="28" Height="28"/>
</Button.Content>
</Button>
这两个动画都没有被触发。我尝试将 VisualStateGroup 的名称更改为 FocusState 并将 VisualState 的名称更改为 Focused,但我也没有看到任何更改。你能告诉我我做错了什么吗?
感谢您的关注!
【问题讨论】:
-
您的故事板没有任何问题,只是您尝试调用它的方式。它只需要做一个控制模板并声明一个资源。我建议查看默认按钮模板以及它如何使用 VisualStateManager,如果这不能很快地揭示您的答案,我们可以很容易地向您展示您缺少的东西,但您离我们不远了。
-
非常感谢您的努力,我已经这样做了,视觉效果达到预期,但我仍然没有发现为什么初始解决方案不好。
-
这只是因为 VisualStateManager 不能直接应用于 UIElement,只需要在 UIElement TargetType 的控件模板中。没什么大不了的,很高兴你找到了你的补救措施。干杯:)
-
谢谢,这就是我想知道的!
标签: windows xaml windows-phone-8 windows-phone visualstatemanager