Friday, January 22, 2010

Controlling Fonts in App

You probably want to have a consistent settings for user controls in your WPF application, at least maybe a default set. Here is a basic example of how to keep Font, Size consistent for such basic controls as TextBlock and Label.

App.xaml:


<Application.Resources>
<
Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
<
Style.Setters>
<
Setter Property="TextBlock.FontFamily" Value="Calibri" />
<
Setter Property="TextBlock.FontSize" Value="11" />
</
Style.Setters>
</
Style>… …

That’s it. This style will jump up itself and initialize listed properties with values specified in this Application level resources. You can still overwrite them in the Forms xaml by explicitly defining them.

0 comments:

Post a Comment