先将样式定义在App.xaml中

<Application.Resources>
        <Style x:Key="MsgTextBlock" TargetType="TextBlock">
            <Setter Property="Height" Value="auto"/>
            <Setter Property="Width" Value="auto"/>
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="Foreground" Value="Blue"/>
            <Setter Property="LineHeight" Value="3"/>
        </Style>
</Application.Resources>

在后台调用:

txtContent.Style = App.Current.Resources["MsgTextBlock"] as Style;

或:

txtContent.Style = Application.Current.Resources["MsgTextBlock"] as Style;

 

posted on 2013-02-04 09:39  NNKOOK  阅读(864)  评论(0编辑  收藏  举报