更改 MouseOver 上超链接按钮的字体粗细
我正在尝试使用 XAML 在 Silverlight 4 中将超链接按钮的文本设为粗体。我尝试修改 HyperlinkButton 模板,但收到 InvalidOperationException: TargetProperty "(Content).FontWeight" 无法解析。
我做错了什么?
....
<ControlTemplate TargetType="HyperlinkButton">
<Grid x:Name="ButtonGrid" Cursor="{TemplateBinding Cursor}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(Content).FontWeight" Duration="0">
<DiscreteObjectKeyFrame KeyTime="0" Value="Bold" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
...
</ControlTemplate>
I am trying to make a the text of a hyperlinkbutton bold in Silverlight 4 using XAML. I have tried modifying the HyperlinkButton template, but I get an InvalidOperationException: TargetProperty "(Content).FontWeight" can not be resolved.
What am I doing wrong?
....
<ControlTemplate TargetType="HyperlinkButton">
<Grid x:Name="ButtonGrid" Cursor="{TemplateBinding Cursor}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(Content).FontWeight" Duration="0">
<DiscreteObjectKeyFrame KeyTime="0" Value="Bold" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
...
</ControlTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我为一个标签创建了两个故事板,然后使用一种行为将它们设置为动画。故事板如下所示。
编辑:我以为您是在问有关一般字体粗细的动画。如果是超链接按钮,您可以编辑内容模板并在其中插入文本块/标签并为其设置动画。
I created two storyboards for a label and then animated them using a behavior. The storyboard looked like below.
Edit: I thought you were asking about animating the font weight in general. In case of a hyperlink button, you could edit the content template and insert a textblock/label inside it and animate that.
ContentPresenter
没有FontWeight
属性。您可以将其更改为ContentControl
并向其应用动画。ContentPresenter
doesn't haveFontWeight
property. You can change it toContentControl
and apply animation to it.