假设我有这样的东西(在MainPage.xaml中):
<Page.Resources>
<Style TargetType="TextBlock" x:Key="TextBlockStyle">
<Setter Property="FontFamily" Value="Segoe UI Light" />
<Setter Property="Background" Value="Navy" />
</Style>
</Page.Resources>
那么,我想将那个 StaticResource 样式应用于我动态创建的 TextBlock(文件 MainPage.xaml.cs)。
有没有可能这样做,而不是像这样做:
myTextBlock.FontFamily = new FontFamily("Segoe UI Light");
myTextBlock.Background = new SolidColorBrush(Color.FromArgb(255,0,0,128));