Gus
Gus

Reputation: 10659

WPF: changing the font of all controls in a given container

How can I change the font of all the child controls in a container, for example a Canvas? I want to have a slider so the user can control the font size of everything in the screen at once.

Thanks

Upvotes: 13

Views: 7026

Answers (1)

alex
alex

Reputation: 75945

The FontSize property of the container should be inherited by child controls unless they explicitly override the property.

<Canvas TextElement.FontSize="20">
    <TextBlock>Sample Text</TextBlock>
</Canvas>

Some controls don't follow the normal inheritance mechanism, however. The ListBox and the Button do not inherit their Background setting from the parent, although they do inherit font properties.

Upvotes: 25

Related Questions