Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add text to a WPF Label in code?

Tags:

c#

wpf

People also ask

How do I wrap text in a label in WPF?

In WPF, the Label control does not support text wrapping. If you need a label that wraps contents across multiple lines, you can use a TextBlock control. Place a TextBlock control inside a Label and apply wrapping on TextBlock.

How do I create a label in WPF?

Creating a WPF LabelThe Width and Height attributes of the Label element represent the width and the height of a Label. The Content property of the Label element sets the text of a Label. The Name attribute represents the name of the control, which is a unique identifier of a control.

How do I add labels in XAML?

A XAML Label element represents a Label control. Code sample of how to use a XAML Label. The code example in Listing 1 creates a Label control in XAML and sets the name, height, width and content of a Label control. The code also sets the font format for the text.


Try DesrLabel.Content. Its the WPF way.


In normal winForms, value of Label object is changed by,

myLabel.Text= "Your desired string";

But in WPF Label control, you have to use .content property of Label control for example,

myLabel.Content= "Your desired string";

I believe you want to set the Content property. This has more information on what is available to a label.


You can use the Content property on pretty much all visual WPF controls to access the stuff inside them. There's a heirarchy of classes that the controls belong to, and any descendants of ContentControl will work in this way.