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 ?
To select all text in a Word document, press Ctrl + A. On the Home tab, click the font size in the Font Size box.
You can apply a style in markup:
<StackPanel.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="20"/>
</Style>
</StackPanel.Resources>
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;
}
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.
You can use styles to apply a value to a property for all TextBlock
s inside the StackPanel
.
Sorry for the previouse wrong answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With