Specify the type of a FrameworkElement in C# WPF

223 Views Asked by At

My method accepts as argument any FrameworkElement. Then it checks if the FrameworkElement is a Label with the condition "if (MyFrameworkElement is Label)". If the condition is true, I want the program to change the FontSize property. But FontSize is not available for a FrameworkElement, I must indicate that it is a Label. How to do it ?

1

There are 1 best solutions below

0
Fruchtzwerg On BEST ANSWER

You can make use of the is operator (Microsoft documentation) described in this article like

if (myFrameworkElement is Label l)
{
    l.FontSize = 123;
}