Silverlight 4 前景色动画
当用户将鼠标悬停在控件上时,我尝试对超链接按钮的前景色进行动画处理。我创建了一个自定义样式,我想在其中对前景色进行动画处理。前景色设置如下
<Setter Property="Foreground" Value="#FF73A9D8"/>
在 VisualStateManager 部分中,我有以下颜色动画元素
<ColorAnimation Duration="0:0:0.5"
Storyboard.TargetName="contentPresenter"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
To="Black" />
问题是我无法弄清楚该值应该是 Storyboard.TargetName。
文本在没有 Foreground 属性的 ContentPresenter 控件中设置
I am trying to animate the Foreground color of a hyperlinkbutton when the user MouseOver the control. I created a custom style in which I want to animate the Foreground color. The Foreground color is set like so
<Setter Property="Foreground" Value="#FF73A9D8"/>
In the visualStateManager section I have the following element for the Color Animation
<ColorAnimation Duration="0:0:0.5"
Storyboard.TargetName="contentPresenter"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
To="Black" />
The problem is that I can not figure out what the value should be Storyboard.TargetName.
The text is set in a ContentPresenter control which does not have a Foreground property
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的。控件模板内没有地方可以悬挂动画。
虽然 HyperlinkButton 有一个前景属性,该属性由其内容继承,但该属性不会作为模板的一部分公开。
最好的选择是创建一个通过 MouseEnter/MouseLeave 行为播放 2 个故事板的用户控件(下面的“GlowingHyperlinkButton”XAML)。当然,您仍然需要通过依赖属性公开内容:
对可怕的颜色选择表示歉意。希望这有帮助:)
You are correct. There is nowhere to hang the animation inside the control template.
While the HyperlinkButton has a foreground property, which is inherited by its content, the property is not exposed as part of the template.
Your best bet is to create a usercontrol that plays 2 storyboards via MouseEnter/MouseLeave behaviours ("GlowingHyperlinkButton" XAML below). You will of course still need to expose the content via a dependency property:
Apologies for the horrid choice of colours. Hope this helps :)