【问题标题】:Specify the type of a FrameworkElement in C# WPF在 C# WPF 中指定 FrameworkElement 的类型
【发布时间】:2020-05-26 06:49:00
【问题描述】:

我的方法接受任何 FrameworkElement 作为参数。然后它检查 FrameworkElement 是否是条件为“if (MyFrameworkElement is Label)”的标签。如果条件为真,我希望程序更改 FontSize 属性。但是FontSize 不适用于FrameworkElement,我必须指出它是一个Label。怎么办?

【问题讨论】:

    标签: c# wpf label frameworkelement


    【解决方案1】:

    您可以使用is 运算符(Microsoft documentation) 中描述的this article 喜欢

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

    【讨论】:

      猜你喜欢
      • 2011-07-04
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多