Search code examples
c#wpfwindows-phone-7textblock

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 ?


Solution

  • 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;
            }