【问题标题】:Changing Label properties programmatically以编程方式更改标签属性
【发布时间】:2009-06-03 22:33:06
【问题描述】:

问题是我需要以编程方式更改 Label FontWeight 和 FontStyle 但似乎没有任何效果......这是我迄今为止尝试过的:

label.FontWeight = FontWeight.FromOpenTypeWeight(99);

对于 label.FontStyle 我不知道,我卡在这里:

label.FontStyle = new FontStyle();

我不知道从那以后该怎么办。我疯狂地用谷歌搜索,但一无所获。

提前感谢您的任何建议!

【问题讨论】:

    标签: wpf wpf-controls label


    【解决方案1】:

    对于 FontStyle,您可以在代码隐藏中使用 FontStyles 类,对于 FontWeight 使用 FontWeights。

            private void Button_Click(object sender, RoutedEventArgs e)
        {
            uiLabel.FontWeight = FontWeights.Bold;
            uiLabel.FontStyle = FontStyles.Italic;
        }
    

    【讨论】:

      【解决方案2】:

      看看this SO question。它本身对标签没有帮助,但它允许您使用 TextBlock 控件更改文本的属性。

      【讨论】:

        猜你喜欢
        • 2014-11-07
        • 1970-01-01
        • 2017-02-27
        • 1970-01-01
        • 2021-09-03
        • 2016-05-22
        • 1970-01-01
        • 2015-10-15
        • 2011-11-28
        相关资源
        最近更新 更多