As far as I remember, in most cases, classes such as TextBlock , TextBox and many others take the color of the text from the TextElement.Foreground property. The property value is inherited throughout the visual tree, i.e. You can set it to the root element, and most of the text will change its color. For instance:
<Grid TextElement.Foreground="Red"> <TextBlock Text="test"/> </Grid>
In fact, the same is true for labels: the default style setter simply sets the TextElement.Foreground to one of the system colors.
However, this is only true for the default state of controls. Altered states, such as highlighting, are not inherited, but rather are taken from system colors, as Rachel wrote.
UPDATE
The same is true for FontSize and FontFamily . They are properties of the TextElement class that attached the use property. They inherit their values. When you set a value in a visual tree element, all its children will receive the same value. If they do not redefine it either by explicit assignment of properties, or by style, etc.
Again, the font color and font family are determined by the TextElement.Foreground , TextElement.FontSize and TextElement.FontFamily property TextElement.FontFamily related dependency properties for a particular visual element.
Some controls, such as Label , explicitly set their Foreground to some brush. It happens so that the brush is one of SystemColors . But this is not necessary for all controls. Others ( TextBlock , TextBox , etc.) do not override the value of the property and simply use some default settings evaluated at startup. The same thing happens with FontSize and FontFamily . You do not need to install them wherever they can work . How does WPF work?
Presumably, the values โโdepend on the system theme. I believe that they are evaluated at application launch time. Perhaps they are customizable.
UPDATE 2
Answers your new questions:
How does TextBlock get its default color if the client application does not provide any style either programmatically or through xaml?
It takes it from the inherited value of the TextElement.Foreground binding TextElement.Foreground . By default, it inherits from the root visual element, which, in turn, is simply set to the default value for the dependency property ( Brushes.Black ). see also
How does Label get its default color?
It takes it from the value of the bound dependency property of TextElement.Foreground . Since its default style sets it to {DynamicResource {x:Static SystemColors.ControlTextBrushKey} , it binds to the color of the system.
How does TextBlock get its default font size and font family if the client application does not provide any style either programmatically or through xaml?
Same as text color. MSDN says that the default font size is SystemFonts.MessageFontSize , which depends on the system settings. A font family is defined in the same way from SystemFonts.MessageFontFamily . Both of these default values โโare passed to the FrameworkPropertyMetadata constructor when the dependency property is registered in the static TextElement constructor.
Next: SystemFonts.MessageFontFamily and SystemFonts.MessageFontSize wrap the internal SystemParameters.NonClientMetrics , which, in turn, is extracted from the WIN32 SystemParametersInfo source file http://msdn.microsoft.com/en-us/library/ms724947 . Thus, WPF is tightly integrated with all Windows UI materials, such as themes, fonts, etc.
How does Label get the default font size and font family?
Same as for TextBlock . Label comes from ContentControl , which in turn comes from Control . Control class adds itself as the owner of the TextElement.FontFamily and TextElement.FontSize with the same default values.
See also:
Property Inheritance
UPDATE 3
You need to understand the basic idea: values โโare inherited. This means that they can be inherited from anywhere, from any control. You can specify exactly which one is inherited only for a specific logical tree structure. You change it a little - and the colors change. Someone sets the property value explicitly - and all children inherit the value. Therefore, your questions are not very practical. But they are still interesting in terms of the lack of rights to WPF.
Override Defaults
Although you cannot change the values โโof the SystemFonts properties (they are read-only), you do not need to. To change the font size and family for the entire window, simply assign the desired TextElement values TextElement attached properties in the Window :
<Window TextElement.FontSize="20" TextElement.FontFamily="Century Gothic"> .. </Window>
and all controls that do not explicitly override inheritance will receive the settings. For those who override - you will have to override the default styles or even throw them away if they hardcode the values.
The same approach works for TextElement.Foreground (and Background , etc.).