在样式中设置TextBlock的前景

时间:2013-09-28 18:23:13

标签: xaml windows-phone-7 styles microsoft-metro

是否可以从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>

1 个答案:

答案 0 :(得分: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设计器中看到效果

相关问题