【问题标题】:Set TextBlock's Foreground in the Style在 Style 中设置 TextBlock 的前景
【发布时间】:2013-09-28 18:23:13
【问题描述】:
是否可以从 Style 中设置 Foreground 属性?看起来好像没有效果。
<Style x:Key="MyPageNameStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" />
<Setter Property="Margin" Value="0,12,0,0"/>
<Setter Property="Foreground" Value="Green"/>
</Style>
【问题讨论】:
标签:
xaml
windows-phone-7
styles
microsoft-metro
【解决方案1】:
确保将其绑定到静态资源很简单
<Grid.Resources>
<Style x:Key="MyPageNameStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" />
<Setter Property="Margin" Value="0,12,0,0"/>
<Setter Property="Foreground" Value="Green"/>
</Style>
</Grid.Resources>
<TextBlock Style="{StaticResource MyPageNameStyle}" Text="WP8 Demodccxzcxzczsczczxcxzczczczcz" Margin="9,-7,0,0" />
您只能在 xaml 设计器中看到效果