经过N次的折腾后,终于解决了Silverlight4的按钮文字变色的问题.
利用MExpressionBlend创建Button的副本,生成Style样式代码,修改如下:
<UserControl.Resources>
<Style x:Key="LoginBtnStyle" TargetType="Button">
...
<Border x:Name="Background"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="White"
CornerRadius="3">
<Grid Background="{TemplateBinding Background}" Margin="1">
<Border x:Name="BackgroundAnimation" Background="#FF448DCA" Opacity="0"/>
<Rectangle x:Name="BackgroundGradient">
<Rectangle.Fill>
<LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
<GradientStop Color="#FFFFFFFF" Offset="0"/>
<GradientStop Color="#F9FFFFFF" Offset="0.375"/>
<GradientStop Color="#E5FFFFFF" Offset="0.625"/>
<GradientStop Color="#C6FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Border>
<ContentPresenter x:Name="contentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}" />
...
</Style>
把<ContentPresenter ... /> 标签改为<TextBlock ..../>
<TextBlock x:Name="btnName"
Text="{TemplateBinding Content}"
...>
添加动画状态,例如MouseOver
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Duration="0"
To="#FF00FF00"
Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="btnName" />
<DoubleAnimation Duration="0"
To="20"
Storyboard.TargetProperty="(TextBlock.FontSize)"
Storyboard.TargetName="btnName" />
<DoubleAnimation ... />
</Storyboard>
</VisualState>
生成项目,运行后,当鼠标移上按钮时,文字颜色,字体大小也改变。
注:暂不清楚<ContentPresenter ... />换成<TextBlock ... />对此按钮会带来怎么样的限制,有待验证。