Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Label properties programmatically

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!

like image 292
Carlo Avatar asked Jun 03 '09 22:06

Carlo


2 Answers

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;
    }
like image 117
rmoore Avatar answered Sep 20 '22 11:09

rmoore


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.

like image 1
Matthew Jones Avatar answered Sep 22 '22 11:09

Matthew Jones