Changing Label properties programmatically

无人久伴 提交于 2019-12-08 21:09:39

问题


The problem is that I need to change Label FontWeight and FontStyle programmatically but nothing seems to work... this is what I've tried so far:

label.FontWeight = FontWeight.FromOpenTypeWeight(99);

For label.FontStyle I have no idea, I got stuck here:

label.FontStyle = new FontStyle();

I have no idea what to do from there on. I googled like crazy but found nothing.

Thanks in advance for any suggestion!


回答1:


For FontStyle you can use the FontStyles class in the code-behind, and for FontWeight use the FontWeights.

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



回答2:


Take a look at this SO question. It doesn't help with the label, per se, but it does allow you to change properties of the text using a TextBlock control.



来源:https://stackoverflow.com/questions/947614/changing-label-properties-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!