2013-09-28 41 views
0

是否可以从样式中设置Foreground属性?看起来没有任何效果。在样式中设置TextBlock的前景

<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> 
+2

这是完全为我工作的影响。 – Xyroid

回答

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" /> 

youll能看到在XAML设计只

相关问题