TextBlock textBlock = new TextBlock(); textBlock.Text = "Hello World!"; textBlock.FontSize = 22;
This code creates a new style called "MyTextBlockStyle" with a font size of 18 and a red foreground color. The style is then applied to a TextBlock control that displays the text "This is a styled TextBlock!".