先將樣式定義在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> 在后臺調(diào)用: txtContent.Style = App.Current.Resources["MsgTextBlock"] as Style; 或: txtContent.Style = Application.Current.Resources["MsgTextBlock"] as Style; |
|