Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the font size of all(n number of ) texblocks inside the stack panel programmatically?

I am creating 'n' number of textblocks inside a stack panel programmatically. I need to change change the font size(both increase and decrease of font size) of 'n' textblocks. Is it possible to change font size of all child's of stack panel in single statement? If not possible how it can be solved efficiently ?

like image 993
tilak Avatar asked Mar 04 '13 07:03

tilak


People also ask

How do I change the whole font size?

To select all text in a Word document, press Ctrl + A. On the Home tab, click the font size in the Font Size box.


4 Answers

You can apply a style in markup:

<StackPanel.Resources>
<Style TargetType="TextBlock">
  <Setter Property="FontSize" Value="20"/>
</Style>
</StackPanel.Resources>
like image 148
Andrei.Mazol Avatar answered Oct 04 '22 00:10

Andrei.Mazol


Yes, You can refer the code snippet below, where 'foobar' refers to your Stackpanel's Name.

        foreach (var children in foobar.Children)
        {
            (children as TextBlock).FontSize = 20;
        }
like image 32
Arun Selva Kumar Avatar answered Oct 04 '22 01:10

Arun Selva Kumar


If you want all Subelements another Style why not use "ContentControl"?

For example like this:

    <GroupBox Header="Some Header" FontSize="18" FontWeight="Bold">
        <ContentControl FontSize="14" FontWeight="Normal">
        ....
        </ContentControl
    <GroupBox>

All elements inside the ContentControl Block will be st with normal weight and a size of 14.
like image 32
Bernd Schuhmacher Avatar answered Oct 04 '22 02:10

Bernd Schuhmacher


You can use styles to apply a value to a property for all TextBlocks inside the StackPanel.

Sorry for the previouse wrong answer.

like image 37
Mohammad Dehghan Avatar answered Oct 04 '22 02:10

Mohammad Dehghan