in WPF It it possible to change a text box’s font size during runtime?
i tried to do that:
foreach (Control ctrl in gridArray[i].Children)
{
if(ctrl.GetType() == typeof(TextBox))
{
(TextBox)ctrl.FontSize = (double)5;
}
}
but it didnt work
The cast does not have a high precedence, your code effectively tries to cast the value in
ctrl.FontSizetoTextBox, you need to add parenthesis (and the double cast is superfluous):Further the way you check the type of the control is not such a good idea, use
isinstead. Otherwise sublasses ofTextBoxare not included.Further as you do not only care about the type and cast as well to interact with the
TextBoxclass interface you may as well useas:This also conveniently gets rid of the parenthesis jungle.