Search code examples
c#wpflabelframeworkelement

Specify the type of a FrameworkElement in C# WPF


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 ?


Solution

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

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